Sharepoint and WCF interactions - c#

I try to read and create XML files on a Sharepoint 2010.
I know that Sharepoint exposed some services used to interract with the application (like /_vti_bin/ListData.svc or /_vti_bin/Lists.asmx or /_vti_bin/Webs.asmx) but i dont know how to use them and if they can do what i want to do.
If someone has a sample to help me or a link with a comprehensive documentation, thank you to please share with us.
Thank you in advance, have a good day.

Here is a reference with examples: http://msdn.microsoft.com/en-us/library/office/aa979690(v=office.14).aspx
Have you tried to search on your own?
What particular problem do you have?

Now i'm able to do what i wanted.
Here is the solution to read XML files on SharePoint 2010 with a WCF Service :
public string GetLocalisationCollection()
{
CopySoapClient client = new CopySoapClient();
FieldInformation myFieldInfo = new FieldInformation();
FieldInformation[] myFieldInfoArray = { myFieldInfo };
byte[] myByteArray;
client.GetItem(Configuration.LocalisationUri, out myFieldInfoArray, out myByteArray);
return System.Text.Encoding.UTF8.GetString(myByteArray);
}

Related

Using the Azure API, how do I list and add virtual directories to a website?

I am trying to add a Virtual Directory to an Azure Web Site from a WinForms Application using the Azure API. I can enumerate the WebSites on in my webspace, but I cannot find a method that allows me access to the Virtual Directories in the WebSite.
Here is my code:
string certPath = Properties.Settings.Default.AzureCertificatePath;
string certPassword = Properties.Settings.Default.AzureCertificatePassword;
string subscriptionId = Properties.Settings.Default.AzureSubscriptionId;
var cert = new X509Certificate2(certPath, certPassword, X509KeyStorageFlags.MachineKeySet);
var cred = new CertificateCloudCredentials(subscriptionId, cert);
using (var client = new WebSiteManagementClient(cred))
{
var spaces = client.WebSpaces.List();
foreach (var space in spaces)
{
Console.WriteLine("Space: {0}", space.Name);
var sites = client.WebSpaces.ListWebSites(space.Name, new WebSiteListParameters {PropertiesToInclude = { "Name" } }); ***// Where do I find out what properties can be included in this array?***
foreach (var site in sites)
{
***// What goes here to show the virtual directories in this specific website??????***
}
}
}
I found that the Azure web services API does not offer access to the virtual directories/applications on a web app, although the underlying REST API's that it uses does.
Luckily, the management API is open source (I wanted to get the v3.0.0.0 of the website management API, matching what I had NuGet'd, which I found here: https://github.com/Azure/azure-sdk-for-net/commits/master?page=79) so with a little perseverance and messing about with .targets files and NuGet references, you can get the source code of the WebSiteManagement project into your solution instead of the referenced DLL that you likely downloaded from NuGet.
From there, if you go into your client.WebSites.GetConfiguration method, stick a breakpoint in and capture the HTTP response returned - you'll see that in the JSON the VirtualApplications on your website are indeed there.
From there, you can edit your copy of the source code to expose those object structures out, much the same way that other object structures are mapped out of the JSON (e.g. HandlerMappings).
Likewise for updating them, you need to add the VirtualApplications (in the ewact same format) into the Microsoft.WindowsAzure.Management.WebSites.Models.WebSiteUpdateConfigurationParameters, and pass that into client.WebSites.UpdateConfiguration (which you will also need to amend to map your VirtualApplications object structure back into JSON in the same format).
Works great for me doing it this way.
Note/Disclaimer: The GitHub site documentation does mention that much of the source code was autogenerated, and that you shouldn't really go editing that code, instead raise an issue on the project about getting it sorted. I didn't have the time to do this and needed an immediate way of getting it working with my local copy of the code only, so my solution does, as you'll note when you look a the source, involve adding to that auto-gen'd code. It works great, but I should in good conscience point you to the project owner's warnings about tinkering with the auto-gen'd code.

Impersonation EPM using PSI or CSOM

For a project I have to sync hours from an external program to EPM. There is no requirement to use the Client Side Object Model of EPM 2013 or the PSI. But because Microsoft recommends the CSOM on their website for all new applications I tried to implement it with the CSOM. The first thing I wanted to test is to get all the hours, with the following code: (It isn't the most beautiful code because it is for testing purposes)
private static void GetTimesheets()
{
ProjectContext projContext = new ProjectContext("http://tfspsdemo/PWA/");
projContext.Load(projContext.TimeSheetPeriods);
projContext.ExecuteQuery();
foreach (var period in projContext.TimeSheetPeriods)
{
projContext.Load(period.TimeSheet);
projContext.ExecuteQuery();
Console.WriteLine(period.Name);
try
{
string tempName = period.TimeSheet.Name;
projContext.Load(period.TimeSheet.Lines);
projContext.ExecuteQuery();
Console.WriteLine(period.TimeSheet.Name);
foreach (var line in period.TimeSheet.Lines)
{
try
{
projContext.Load(line);
projContext.Load(line.Work);
projContext.ExecuteQuery();
foreach (var workLine in line.Work)
{
Console.WriteLine(workLine.ActualWork);
}
}
catch (Exception) { }
Console.WriteLine("Total: {0}", line.TotalWork);
}
}
catch (ServerObjectNullReferenceException) { }
}
}
But with above code I get only the code for the current user that is logged in, even if it is a person with rights to see other users hours. But what I want is to see all the hours of all the persons that have booked hours in EPM for a specific project plan. So I can later use this information to sync the hours from an external program to EPM. I thought I can solve this with impersonation but:
ProjectContext projContext = new ProjectContext("http://tfspsdemo/PWA/");
projContext.Credentials = new NetworkCredentials("username", "password");
But this isn't what I want because I have to do this for each user. And also I can't get the passwords of all users.
Does anyone now a solution to solve this problem and/or any suggestions? Solutions with the EPM PSI are also appreciated!
Thanks in advance!
Impersonation is not yet implemented in Project Sever 2016/Project Online. Please vote here: https://microsoftproject.uservoice.com/forums/218133-microsoft-project/suggestions/32981722-impersonation-support-for-csom-to-read-other-user
Thanks,
Werner
There are two modes in Proect server 2013. Proect server and SharePoint mode. I was able to get the above working in SharePoint mode, but alas I cannot read even Timesheet Periods as it says CSOMUnkownUser in Project server mode even after passing in the credentials. What mode are you running in currently on the server
This is probably a little late, but to access that kind of data in a provider/auto hosted app you need to access the sharepoint server through OData. CSOM is only intended to provide data from the current user context.

saving get data to a local variable

I was wondering is there a way to save get parameters that the website sends to the server to be saved to a local variable via java script. something like a cookie or the session variable.
EDIT 1:
I am also willing to save it to a server-side cookie, but i still don't know how to do that.
i am using MVC4 in VisualStudio with C# as server-side lang. if there is an easier method to do it server side I'm up for that.
EDIT 2
The comment game me an idea, and i managed to get the solution via the session class server-side. thanks ppl :)
function getUrlParams() {
var params = {};
window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) {
params[key] = value;
});
return params;
}
Using the Session.AddItem method i was able to save all the data i needed. thanks for your help guys.

Modify the content of the home page programmatically in SharePoint 2010

First of all, I'm pretty new to SharePoint so don't shoot me if this is a noobish question or if I don't provide all the right information at once... :)
I have a team-site in SharePoint with following URL: "http://myServer/Opdracht_Ben/". By going to this URL I'm redirected to following page: "http://myServer/sites/Opdracht_Ben/SitePages/Home.aspx".
In Visual Studio I have a project for this site with a feature. When this site-feature is activated it should change the content of the home-page to some custom tekst and layout (i.e.: HTML). The content is not contained within a web part or the page is not a WikiPage, just text on a page.
I've been looking on MSDN and on several tech-sites and blogs but I have not found anything that could help me further. Does anyone know how I can 'reach' the content of the page and modify/update it?
PS:
Here on SO I have found a related question (Click for the question), but the provided solution is for when the web is a "Publishing Web", which is not the case here, so that solution won't do me any good.
Thanks in advance!
I have found out that the page IS a WikiPage after all. So I managed to change the content with following code:
using (var site = new SPSite(ApplicationResources.Url.SiteRoot))
{
using (var web = site.OpenWeb())
{
var page = web.GetFile(ApplicationResources.Url.FullDefaultPageName);
var item = page.Item;
item["Wiki Content"] = NewContent(title, text);
item.Update();
}
}
Maybe this is not the best method, so if anyone has a better and more reliable solution: feel free to correct me! ;)

How do I get Google Calendar feed from user's access token?

Using OAuth I do get access token from Google. The sample that comes with Google and even this one:
http://code.google.com/p/google-api-dotnet-client/source/browse/Tasks.SimpleOAuth2/Program.cs?repo=samples
show how to use Tasks API. However, I want to use Calendar API. I want to get access to user's calendar. Can anybody tell me how do I do that?
Take a look at the samples:
Getting Started with the .NET Client Library
On the right side of the page linked above there is a screen shot showing the sample projects contained in the Google Data API solution. They proofed to be very helpful (I used them to start my own Google Calendar application).
I recommend keeping both your own solution and the sample solution open. This way you can switch between the examples and your own implementation.
I also recommend to use the NuGet packages:
Google.GData.AccessControl
Google.GData.Calendar
Google.GData.Client
Google.GData.Extensions
and more ...
This way you easily stay up to date.
Sample to get the users calendars:
public void LoadCalendars()
{
// Prepare service
CalendarService service = new CalendarService("Your app name");
service.setUserCredentials("username", "password");
CalendarQuery query = new CalendarQuery();
query.Uri = new Uri("https://www.google.com/calendar/feeds/default/allcalendars/full");
CalendarFeed calendarFeed = (CalendarFeed)service.Query(query);
Console.WriteLine("Your calendars:\n");
foreach(CalendarEntry entry in calendarFeed.Entries)
{
Console.WriteLine(entry.Title.Text + "\n");
}
}

Categories