We all know that in CSOM, for any given object, we can specify certain properties to be brought back from the server. Something like this:
This will only bring back the Title property of the web thus reducing data traveling over the wire.
Now in this case, the second parameter of the clientContext.Load method is an object of type Expression<Func<Web, object>>[]
This is an array of Linq expressions which can be utilized to our benefit. We can convert that array into a parameter which can be passed to a "Utility" function. This function will only get the properties specified in that array. Like this:
Then, that function can be called with different parameters depending on the properties we want to fetch from the server for that particular instance. For example:
Only get the Title and Id of the Web:
Only get the MasterUrl and the CustomMasterUrl of the web:
For both the above calls, we are not changing the GetWebDetails function. It will always return a Web object with the specified properties filled in. It will also reduce data travelling over the wire, as only the specified properties will be fetched. Thus, making your code more flexible and performance friendly.
You can also have other utility functions for Lists, Users etc. Here is a similar function for Lists:
Hope you find this useful!
Showing posts with label Client Object Model. Show all posts
Showing posts with label Client Object Model. Show all posts
Wednesday, 25 March 2015
Saturday, 31 May 2014
Using the SharePoint 2013 Workflow Interop Service in CSOM
In my previous post, I briefly introduced the SharePoint 2013 Workflow Architecture and also showed how to programmatically manage the SharePoint 2013 Workflows via the Workflow Services in the Client Site Object Model (CSOM). I will recommend to read that post before this one.
You can find the previous post here: Managing SharePoint 2013 Workflows with CSOM
As a follow up to that post, in this post I will show how to start a Workflow authored with the SharePoint 2010 Engine.
The Workflow Services in the CSOM contain an InteropService which is a hook in the SharePoint 2010 Windows Workflow Foundation runtime engine.
This code works with SharePoint 2013 On-Premises as well as with SharePoint Online. I have created my sample code against SharePoint Online.
Before you run this code, you will need to create a SharePoint 2010 Workflow (Definition) either via SharePoint Designer 2010/2013 or through Visual Studio 2012/2013 and deploy it to your SharePoint 2013 target site. You can then use this code to start the Workflow
You will need to reference the following Assemblies:
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.SharePoint.Client.WorkflowServices.dll
You can find the previous post here: Managing SharePoint 2013 Workflows with CSOM
As a follow up to that post, in this post I will show how to start a Workflow authored with the SharePoint 2010 Engine.
The Workflow Services in the CSOM contain an InteropService which is a hook in the SharePoint 2010 Windows Workflow Foundation runtime engine.
This code works with SharePoint 2013 On-Premises as well as with SharePoint Online. I have created my sample code against SharePoint Online.
Before you run this code, you will need to create a SharePoint 2010 Workflow (Definition) either via SharePoint Designer 2010/2013 or through Visual Studio 2012/2013 and deploy it to your SharePoint 2013 target site. You can then use this code to start the Workflow
You will need to reference the following Assemblies:
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.SharePoint.Client.WorkflowServices.dll
1) Start a SharePoint 2010 Site Workflow with CSOM:
2) Start a SharePoint 2010 List Workflow with CSOM:
Managing SharePoint 2013 Workflows with CSOM
As you might have heard many times, the Workflow Architecture in SharePoint 2013 was entirely changed from what it was in SharePoint 2010. Instead of the Workflows running on the SharePoint server, they now have to run on a separate Workflow Manager.
On top of that, only declarative custom Workflow's are allowed to be deployed to the Workflow Manager. If there has to be any custom code, it has to be hosted in an external service and then consumed from the declarative workflow.
The Workflow Manager has certain activities and types which come predefined with it. This is called the Trusted Surface. Workflow Authors can consume these activities in their declarative workflows. A whole list of types and activities available under the trusted surface is here: http://msdn.microsoft.com/en-us/library/jj193509(v=azure.10).aspx and here: http://msdn.microsoft.com/en-us/library/jj193474(v=azure.10).aspx
This architecture is very much inline with Microsoft's strategy to move code execution away from the SharePoint server.
On top of that, only declarative custom Workflow's are allowed to be deployed to the Workflow Manager. If there has to be any custom code, it has to be hosted in an external service and then consumed from the declarative workflow.
The Workflow Manager has certain activities and types which come predefined with it. This is called the Trusted Surface. Workflow Authors can consume these activities in their declarative workflows. A whole list of types and activities available under the trusted surface is here: http://msdn.microsoft.com/en-us/library/jj193509(v=azure.10).aspx and here: http://msdn.microsoft.com/en-us/library/jj193474(v=azure.10).aspx
This architecture is very much inline with Microsoft's strategy to move code execution away from the SharePoint server.
SharePoint 2013 supports two methods of workflow authoring. Authoring Workflows in the SharePoint 2013 engine and also authoring them in the SharePoint 2010 engine. Workflows which are authored in the SharePoint 2010 engine run on the SharePoint server and are allowed to execute code there. That architecture has not been changed and is available for backwards compatibility.
In the SharePoint 2013 Workflow platform, a Workflow definition is a Service Bus Topic and a Workflow Association is a Subscription to the topic. Topics and Subscriptions are used by the Service Bus to decouple message publishers from message subscribers. More about the Workflow Manager and Service Bus Pub/Sub architecture here: http://msdn.microsoft.com/en-us/library/office/jj163181(v=office.15).aspx#bkm_Subscriptions
In the SharePoint 2013 Workflow platform, a Workflow definition is a Service Bus Topic and a Workflow Association is a Subscription to the topic. Topics and Subscriptions are used by the Service Bus to decouple message publishers from message subscribers. More about the Workflow Manager and Service Bus Pub/Sub architecture here: http://msdn.microsoft.com/en-us/library/office/jj163181(v=office.15).aspx#bkm_Subscriptions
Microsoft has also very recently added Workflow Management services to the Client Side Object Model (CSOM). The entire range of Workflow services available in the CSOM is published here: http://msdn.microsoft.com/en-us/library/office/dn481315(v=office.15).aspx. In this post, and the following posts, I will show you how to manage workflows with CSOM.
This is code works with SharePoint 2013 On-Premises as well as with SharePoint Online. I have created my sample code against SharePoint Online. Also, this code only works with Workflows which are authored on the SharePoint 2013 Workflow Engine. I will be writing another post on the CSOM Interop Service in which I will show how to start SharePoint 2010 Workflow Engine authored Workflows.
Before you run this code, you will need to create a Workflow (Definition) either via SharePoint Designer 2013 or through Visual Studio 2012/2013 and deploy it to your target site. You can then use this code to dynamically create associations of the Workflow, and also to start those associations.
You will need to reference the following Assemblies:
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.SharePoint.Client.WorkflowServices.dll
1) Create a new Subscription (Association) from a Workflow Definition with CSOM:
2) Start a SharePoint 2013 Site Workflow with CSOM:
3) Start a SharePoint 2013 List Workflow with CSOM:
Wednesday, 5 March 2014
View Tenant (ULS) Logs in SharePoint Online using CSOM
Update (14th Sep 2014): Even though the classes exist in the CSOM, the Microsoft Office 365 Engineering team has confirmed that this is something which is not possible right now. It is also something which is not currently on their road map. They have said that if there is high demand for this feature, they will look into implementing it. Please go to the Office 365 UserVoice site and vote this feature up if you are interested: http://officespdev.uservoice.com/forums/224641-general/suggestions/4578386-provide-a-way-to-view-uls-logs-on-sharepoint-onlin
----------------------------------------------------------X-------------------------------------------------
A while ago, I came across the Office365 UserVoice site. It was a good way to give feedback and let the SharePoint/Office365 team know which features could make the life of SharePoint Developers easy.
I decided to post on it a feature request, which I felt was desperately needed and would really help me as a SharePoint Developer: A way to view ULS Logs on SharePoint Online
http://officespdev.uservoice.com/forums/224641-general/suggestions/4578386-provide-a-way-to-view-uls-logs-on-sharepoint-onlin
It seems this was a shared opinion among many people and the request went on to become one of the top voted on the site:
http://officespdev.uservoice.com/forums/224641-general/filters/top
Fast Forward to today and I was really excited about the SharePoint Conference 2014! I saw a lot of code samples and articles being published as a result of the new features introduced by the SharePoint Team. While exploring the Office App Model Samples (http://officeams.codeplex.com/) I came across the following DLL: Microsoft.Online.SharePoint.Client.Tenant.dll
You can refer to my previous post about using this DLL to create Site Collections in SharePoint Online:
http://www.vrdmn.com/2014/03/create-site-collections-with-csom-in.html
I opened up the DLL in ILSpy and immediately noticed the TenantLog class:
http://msdn.microsoft.com/en-us/library/microsoft.online.sharepoint.tenantadministration.tenantlog_members(v=office.15).aspx
After playing around it a bit, I was able to retrieve Log messages from my Tenant. This seems to be a preview feature still in development and was not working on all the tenants on which I tested. In fact, it was working only on a newly created Tenant! That too only for the Developer Site.
Having a look at the MSDN docs for the SPO PowerShell cmdlet:
http://technet.microsoft.com/en-us/library/fp161369(v=office.15).aspx
"This function cannot retrieve all SharePoint Online errors. It retrieves a subset of errors that happen due to external systems.
For Beta 2, the only logs available are for Business Connectivity Services (BCS)."
I will keep this post updated with any new information which comes along.
You will need the following DLLs for this code to work:
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.Online.SharePoint.Client.Tenant.dll
The first two assemblies can be found in the ISAPI folder of your SharePoint 2013 Server Box. The Microsoft.Online.SharePoint.Client.Tenant.dll is a part of the SharePoint Server 2013 Client Components SDK which can downloaded from here: http://www.microsoft.com/en-in/download/details.aspx?id=35585
So without much further ado, here is the code:
And here is the output I got after running the code:
I think the SharePoint team has done a really great job of listening to the community to add new features to SharePoint/Office365 and I am really happy!
----------------------------------------------------------X-------------------------------------------------
A while ago, I came across the Office365 UserVoice site. It was a good way to give feedback and let the SharePoint/Office365 team know which features could make the life of SharePoint Developers easy.
I decided to post on it a feature request, which I felt was desperately needed and would really help me as a SharePoint Developer: A way to view ULS Logs on SharePoint Online
http://officespdev.uservoice.com/forums/224641-general/suggestions/4578386-provide-a-way-to-view-uls-logs-on-sharepoint-onlin
It seems this was a shared opinion among many people and the request went on to become one of the top voted on the site:
http://officespdev.uservoice.com/forums/224641-general/filters/top
Fast Forward to today and I was really excited about the SharePoint Conference 2014! I saw a lot of code samples and articles being published as a result of the new features introduced by the SharePoint Team. While exploring the Office App Model Samples (http://officeams.codeplex.com/) I came across the following DLL: Microsoft.Online.SharePoint.Client.Tenant.dll
You can refer to my previous post about using this DLL to create Site Collections in SharePoint Online:
http://www.vrdmn.com/2014/03/create-site-collections-with-csom-in.html
I opened up the DLL in ILSpy and immediately noticed the TenantLog class:
http://msdn.microsoft.com/en-us/library/microsoft.online.sharepoint.tenantadministration.tenantlog_members(v=office.15).aspx
After playing around it a bit, I was able to retrieve Log messages from my Tenant. This seems to be a preview feature still in development and was not working on all the tenants on which I tested. In fact, it was working only on a newly created Tenant! That too only for the Developer Site.
Having a look at the MSDN docs for the SPO PowerShell cmdlet:
http://technet.microsoft.com/en-us/library/fp161369(v=office.15).aspx
"This function cannot retrieve all SharePoint Online errors. It retrieves a subset of errors that happen due to external systems.
For Beta 2, the only logs available are for Business Connectivity Services (BCS)."
I will keep this post updated with any new information which comes along.
You will need the following DLLs for this code to work:
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.Online.SharePoint.Client.Tenant.dll
The first two assemblies can be found in the ISAPI folder of your SharePoint 2013 Server Box. The Microsoft.Online.SharePoint.Client.Tenant.dll is a part of the SharePoint Server 2013 Client Components SDK which can downloaded from here: http://www.microsoft.com/en-in/download/details.aspx?id=35585
So without much further ado, here is the code:
And here is the output I got after running the code:
I think the SharePoint team has done a really great job of listening to the community to add new features to SharePoint/Office365 and I am really happy!
Tuesday, 4 March 2014
Create Site Collections with CSOM in SharePoint Online
With the SharePoint Conference 2014, a lot of code samples and articles where recently released. I was most impressed by the Office App Model Samples found here: http://officeams.codeplex.com/
Within that, there is some really good code of which my favorite is Creating Site Collections in SharePoint Online with CSOM. Previously this was only possible via Powershell and the SharePoint Online (SPO) Commandlets. I have modified the code provided in the samples to make it a bit less complex and you can also use it outside of an app e.g. in console applications.
You will need the following DLLs for this code to work:
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.Online.SharePoint.Client.Tenant.dll
The first two assemblies can be found in the ISAPI folder of your SharePoint 2013 Server Box. The Microsoft.Online.SharePoint.Client.Tenant.dll is a part of the SharePoint Server 2013 Client Components SDK which can downloaded from here: http://www.microsoft.com/en-in/download/details.aspx?id=35585
So without much further ado, here is the code:
Within that, there is some really good code of which my favorite is Creating Site Collections in SharePoint Online with CSOM. Previously this was only possible via Powershell and the SharePoint Online (SPO) Commandlets. I have modified the code provided in the samples to make it a bit less complex and you can also use it outside of an app e.g. in console applications.
You will need the following DLLs for this code to work:
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.Online.SharePoint.Client.Tenant.dll
The first two assemblies can be found in the ISAPI folder of your SharePoint 2013 Server Box. The Microsoft.Online.SharePoint.Client.Tenant.dll is a part of the SharePoint Server 2013 Client Components SDK which can downloaded from here: http://www.microsoft.com/en-in/download/details.aspx?id=35585
So without much further ado, here is the code:
Friday, 29 November 2013
Set UserProfile Picture using Client APIs in SharePoint 2013
With the SharePoint 2013 Client APIs, you can only read the User Profile Properties but not modify them. However the only property you can modify is the Current User's profile picture. Source article: http://msdn.microsoft.com/en-us/library/jj920104.aspx
The REST API expects the image to be in the arraybuffer format in order to be set. To convert an image to arraybuffer, we will be using the XMLHttpRequest object
The XMLHttpRequest object allows us to specify the format in which we want the content to be downloaded. The available options are: arraybuffer, blob, json, text, document and some other browser specific formats.
Complete documentation for the XMLHttpRequest object:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
Also a very good article on how to use the XMLHttpRequest object:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest
A very important point to note is that XMLHttpRequest will work with cross domain images only if the server which is hosting the images allows cross domain requests to be made.
Modern browsers support cross-site requests by implementing the web applications working group's Access Control for Cross-Site Requests standard. As long as the server is configured to allow requests from your web application's origin, XMLHttpRequest will work. Otherwise, an INVALID_ACCESS_ERR exception is thrown.
For the sake of simplicity, we will be using the images hosted in the same domain as SharePoint itself so we do not have to worry about cross domain requests.
The REST API expects the image to be in the arraybuffer format in order to be set. To convert an image to arraybuffer, we will be using the XMLHttpRequest object
The XMLHttpRequest object allows us to specify the format in which we want the content to be downloaded. The available options are: arraybuffer, blob, json, text, document and some other browser specific formats.
Complete documentation for the XMLHttpRequest object:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
Also a very good article on how to use the XMLHttpRequest object:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest
A very important point to note is that XMLHttpRequest will work with cross domain images only if the server which is hosting the images allows cross domain requests to be made.
Modern browsers support cross-site requests by implementing the web applications working group's Access Control for Cross-Site Requests standard. As long as the server is configured to allow requests from your web application's origin, XMLHttpRequest will work. Otherwise, an INVALID_ACCESS_ERR exception is thrown.
For the sake of simplicity, we will be using the images hosted in the same domain as SharePoint itself so we do not have to worry about cross domain requests.
1) Set Current User's UserProfile Picture using the REST API:
2) Set Current User's UserProfile Picture using the .NET Managed Client Object Model:
This is relatively easy as the SetMyProfilePicture managed method expects the image to be a System.IO.Stream.
This code assumes you are working with SharePoint Online/Office 365. If you are working with an On-Premise deployment, you do not need to use the SharePointOnlineCredentials class. You can simply create an instance of the NetworkCredentials class for the authentication.
Monday, 15 July 2013
Batch Operations using the JavaScript Client Object Model
To improve performance and to reduce the time taken for data to travel over the wire, we can do batch operations using the Client Object Model in SharePoint. This can really help in reducing load time of pages and make the user experience better. Batch operations can be done using the .NET as well as the JavaScript Client Object Model. In this post, we are going to focus on how to perform batch operations using the JavaScript Client Object Model. In each of the following operations, only one call from the client to server will be made. It will contain all the information needed to perform the necessary operation. So without further ado, here is the code:
Now as you can see, only one call is made from the client to the server. It contains all the XML necessary for creating the 5 items. Here is the relevant XML:
Hope you enjoyed this blog post. Happy SharePointing!
Addendum: I would also like to point out one of the hidden gems of the SharePoint world: if you are using Server Side Code (Full Trust), there is a similar batch method available called SPWeb.ProcessBatchData which can be used to bulk add, edit and delete list items. This is really helpful because it can operate on large number of items at once without making repeated calls to the database.
1) Batch Add Items to List:
2) Batch Update Items from List:
3) Batch Delete Items from List:
Now let us analyze what happens behind the scenes when we make one of these batch operations. Here is the firebug screen grab of the call to batch create 5 items:Now as you can see, only one call is made from the client to the server. It contains all the XML necessary for creating the 5 items. Here is the relevant XML:
Hope you enjoyed this blog post. Happy SharePointing!
Addendum: I would also like to point out one of the hidden gems of the SharePoint world: if you are using Server Side Code (Full Trust), there is a similar batch method available called SPWeb.ProcessBatchData which can be used to bulk add, edit and delete list items. This is really helpful because it can operate on large number of items at once without making repeated calls to the database.
Saturday, 12 January 2013
Authenticating .NET CSOM in SharePoint Online
The process of authenticating the .NET Client Object Model in SharePoint Online has been greatly simplified in the 2013 version. Earlier (2010), you had to go through a lot of steps for doing the exact same thing. You had to open a web browser instance, force the user to enter the credentials in the browser and then grab that cookie from Internet Explorer and pass it to the .NET CSOM. If you are interested, the code of the old authentication method can be found here:
http://blogs.msdn.com/b/cjohnson/archive/2011/05/03/authentication-with-sharepoint-online-and-the-client-side-object-model.aspx
Fortunately in the 2013 version, the process is a lot simplified by the introduction of the SharePointOnlineCredentials class. This class is part of the Microsoft.SharePoint.Client.dll itself so you don't have to include an extra assembly in your application. All you have to do is pass an instance of the SharePointOnlineCredentials class to the ClientContext.Credentials property. The SharePointOnlineCredentials takes in two parameters which are your Login Email for your Office 365 SharePoint site and your password in the SecureString format.
You can grab all the required SharePoint 2013 client assemblies from here:
http://www.microsoft.com/en-us/download/details.aspx?id=35585
For this particular demo, you will need to reference the Microsoft.SharePoint.Client.dll and the Microsoft.SharePoint.Client.Runtime.dll assemblies in your project.
The code is as follows:
http://blogs.msdn.com/b/cjohnson/archive/2011/05/03/authentication-with-sharepoint-online-and-the-client-side-object-model.aspx
Fortunately in the 2013 version, the process is a lot simplified by the introduction of the SharePointOnlineCredentials class. This class is part of the Microsoft.SharePoint.Client.dll itself so you don't have to include an extra assembly in your application. All you have to do is pass an instance of the SharePointOnlineCredentials class to the ClientContext.Credentials property. The SharePointOnlineCredentials takes in two parameters which are your Login Email for your Office 365 SharePoint site and your password in the SecureString format.
You can grab all the required SharePoint 2013 client assemblies from here:
http://www.microsoft.com/en-us/download/details.aspx?id=35585
For this particular demo, you will need to reference the Microsoft.SharePoint.Client.dll and the Microsoft.SharePoint.Client.Runtime.dll assemblies in your project.
The code is as follows:
Monday, 27 August 2012
Paging in SharePoint JavaScript Client Object Model
Paging can be of great help when you want to improve the performance of your code especially when you are working on front-end development and want to reduce the page response time. Let us see how can be implement paging when working with the JavaScript Client Object Model.
The important parts to note in this code are the RowLimitelement in the CAML query and the SP.ListItemCollection.get_listItemCollectionPosition(); property. Please have a look at the comments to know more details about the individual lines of code.
The important parts to note in this code are the RowLimit
The ListItemCollectionPosition.pagingInfo determines the id of the last item fetched along with the filter and sorting criteria. It specifies information, as name-value pairs, required to get the next page of data for a list view.
Sunday, 15 May 2011
Add Web Part to Page using SharePoint Client Object Model:File not Found error.
When adding a web part to your page if you get the "file not found" error there is one small trick which you probably have to do.
You will most probably get this error if the page you are adding the web part to, is not in the root site of the site collection.
Here is the code to add a web part to your SharePoint page:
ClientContext clientcontext = new ClientContext("http://vardhaman/Sites/zevenseas/");
Microsoft.SharePoint.Client.File page = clientcontext.Web.GetFileByServerRelativeUrl("/Sites/zevenseas/SitePages/Home.aspx");
LimitedWebPartManager wpm = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
string webpartxml = /*The webpart XML */;
WebPartDefinition wpd = wpm.ImportWebPart(webpartxml);
wpm.AddWebPart(wpd.WebPart, "Left", 1);
clientcontext.ExecuteQuery();
Notice that I have passed the entire url of the site when creating the ClientContext object. And also when I have to fetch the page to which the webpart should be added, I have passed the entire site relative url which includes the name of the site which I initially passed to the ClientContext Object.
I was stuck on this error for sometime because I tought that once I had passed the site URL ("http://vardhaman/Sites/zevenseas/") to the ClientContext object, I need to only pass the location of the page within the site ("/SitePages/Home.aspx") when fetching the page. But that did not turn out to be the case.
Have Fun Coding!
You will most probably get this error if the page you are adding the web part to, is not in the root site of the site collection.
Here is the code to add a web part to your SharePoint page:
ClientContext clientcontext = new ClientContext("http://vardhaman/Sites/zevenseas/");
Microsoft.SharePoint.Client.File page = clientcontext.Web.GetFileByServerRelativeUrl("/Sites/zevenseas/SitePages/Home.aspx");
LimitedWebPartManager wpm = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
string webpartxml = /*The webpart XML */;
WebPartDefinition wpd = wpm.ImportWebPart(webpartxml);
wpm.AddWebPart(wpd.WebPart, "Left", 1);
clientcontext.ExecuteQuery();
Notice that I have passed the entire url of the site when creating the ClientContext object. And also when I have to fetch the page to which the webpart should be added, I have passed the entire site relative url which includes the name of the site which I initially passed to the ClientContext Object.
I was stuck on this error for sometime because I tought that once I had passed the site URL ("http://vardhaman/Sites/zevenseas/") to the ClientContext object, I need to only pass the location of the page within the site ("/SitePages/Home.aspx") when fetching the page. But that did not turn out to be the case.
Have Fun Coding!
Wednesday, 27 April 2011
Get HTML from page using the Client Object Model in SharePoint
Here is how to get the RAW HTML of a Web Page on your SharePoint Site using the Client Object Model:
Just substitute your Site Collection name instead of "sitecollection" and your page path along with the Relative Server URL instead of /Sites/Vard/SitePages/Home.aspx
The string variable pageHTML will now have the raw html of the Home.aspx page.
Have Fun!
Just substitute your Site Collection name instead of "sitecollection" and your page path along with the Relative Server URL instead of /Sites/Vard/SitePages/Home.aspx
The string variable pageHTML will now have the raw html of the Home.aspx page.
Have Fun!
Monday, 25 April 2011
Office365 beta and the SharePoint 2010 Client Object Model
UPDATE: Microsoft has published the article on Authentication the Client Object Model on Office 365. You can find it here:
http://blogs.msdn.com/b/cjohnson/archive/2011/05/03/authentication-with-sharepoint-online-and-the-client-side-object-model.aspx
-------XXX-------
I just got my Office365 beta license and configured a new Team Site in Sharepoint Online. Then I thought of accessing this new team site through the SharePoint 2010 .NET Client Object Model when I got the 403: Forbidden error code.
First, I thought that there might be some authenticaion issue so I tried accessing with both Classic Authentication and Claims based authentication.
Forms Based Authentication(Client Object Model):
clientcontext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
clientcontext.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo("username", "password");
Web Service Login:
AuthService.Authentication auth = new AuthService.Authentication();
auth.Url = "http://.sharepoint.com/TeamSite/_vti_bin/authentication.asmx";
auth.CookieContainer = new System.Net.CookieContainer();
AuthService.LoginResult loginresult = auth.Login("username","password");
With both the cases, it gave me the following error:
"Server was unable to process request. ---> The server was unable to process the request due to an internal error."
lists.asmx:
I tried accessing the lists of Office365 through the Lists service:
ListService.Lists list = new ListService.Lists();
list.Credentials = new NetworkCredential("username", "password");
var res = list.GetList("Documents");
but got this clear cut error:
"Server was unable to process request. ---> Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
After some digging aroung, I found out that indeed right now, support is not there for the client object model and the only way to currently use the Client Object Model with SharePoint Online is to get the FedAuth Cookie (from fiddler) and then include that cookie in your call from the code. But this is not the best practice and is highly discouraged.
Hopefully, the Office 365 team will include the Client Object Model as soon as possible. I will update it here as soon as there is any news regarding the issue.
http://blogs.msdn.com/b/cjohnson/archive/2011/05/03/authentication-with-sharepoint-online-and-the-client-side-object-model.aspx
-------XXX-------
I just got my Office365 beta license and configured a new Team Site in Sharepoint Online. Then I thought of accessing this new team site through the SharePoint 2010 .NET Client Object Model when I got the 403: Forbidden error code.
First, I thought that there might be some authenticaion issue so I tried accessing with both Classic Authentication and Claims based authentication.
Forms Based Authentication(Client Object Model):
clientcontext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
clientcontext.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo("username", "password");
Web Service Login:
AuthService.Authentication auth = new AuthService.Authentication();
auth.Url = "http://
auth.CookieContainer = new System.Net.CookieContainer();
AuthService.LoginResult loginresult = auth.Login("username","password");
With both the cases, it gave me the following error:
"Server was unable to process request. ---> The server was unable to process the request due to an internal error."
lists.asmx:
I tried accessing the lists of Office365 through the Lists service:
ListService.Lists list = new ListService.Lists();
list.Credentials = new NetworkCredential("username", "password");
var res = list.GetList("Documents");
but got this clear cut error:
"Server was unable to process request. ---> Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
After some digging aroung, I found out that indeed right now, support is not there for the client object model and the only way to currently use the Client Object Model with SharePoint Online is to get the FedAuth Cookie (from fiddler) and then include that cookie in your call from the code. But this is not the best practice and is highly discouraged.
Hopefully, the Office 365 team will include the Client Object Model as soon as possible. I will update it here as soon as there is any news regarding the issue.
Subscribe to:
Posts (Atom)

