SharePoint Client Object Model for SharePoint Server and Office365 difference
This post will show you a minor difference between creating a SharePoint Server COM application and a Office 365 COM application. This is really quick and easy ;)
Alright! First for the SharePoint Server COM application. I've created a C# console application.
Add these references for the application.
Create a COM function, for now I'll show you how to create a site. The rest of the COM functions, I'll show on another tutorial. ;)
Now to modify this application so it would work for Office365 SharePoint Server. Just add this dll reference on the application. This is for the authentication side which Office365 uses.
Then we'll just have to modify the client context connection.
Notice the changes made on the function. You can play around with it, like adding parameters when accessing the console application. Run the application and check the changes in your SharePoint Server. I find the console application much better to work with if I have a main application that needs to interact with SharePoint(but you can do a UI application too). Next tutorial, I'll give other COM function samples and using the web references. Ka-ciao! ;)
Alright! First for the SharePoint Server COM application. I've created a C# console application.
Add these references for the application.
using Microsoft.SharePoint.Client; using Microsoft.SharePoint;
Create a COM function, for now I'll show you how to create a site. The rest of the COM functions, I'll show on another tutorial. ;)
namespace SP_COMapplication { class Program { static void Main(string[] args) { CreateSite(); } public static void CreateSite() { using (ClientContext ctx= new ClientContext("http://sharepoint server url")) { if (ctx != null) { string blogDescription = "Sample Site"; int blogLanguage = 1033; string blogTitle = "COM Site"; string blogUrl = "sample00"; bool blogPermissions = false; string webTemplate = "STS#1"; Web web = ctx.Web; WebCreationInformation webCreateInfo = new WebCreationInformation(); webCreateInfo.Description = blogDescription; webCreateInfo.Language = blogLanguage; webCreateInfo.Title = blogTitle; webCreateInfo.Url = blogUrl; webCreateInfo.UseSamePermissionsAsParentSite = blogPermissions; webCreateInfo.WebTemplate = webTemplate; Web oNewWebsite = web.Webs.Add(webCreateInfo); oNewWebsite.QuickLaunchEnabled = true; ctx.Load( oNewWebsite, website => website.ServerRelativeUrl, website => website.Created); ctx.ExecuteQuery(); } } } } }
Now to modify this application so it would work for Office365 SharePoint Server. Just add this dll reference on the application. This is for the authentication side which Office365 uses.
using MSDN.Samples.ClaimsAuth;
Then we'll just have to modify the client context connection.
namespace SP_COMapplication { class Program { [STAThread]//to avoid threading error, this is a special case where we have to use the single thread for the application static void Main(string[] args) { CreateSite(); } public static void CreateSite() { string targetSite = "https://office365sharepoint site url"; using (ClientContext ctx = ClaimClientContext.GetAuthenticatedContext(targetSite)) { if (ctx != null) { string blogDescription = "Sample Site"; int blogLanguage = 1033; string blogTitle = "COM Site"; string blogUrl = "sample00"; bool blogPermissions = false; string webTemplate = "STS#1"; Web web = ctx.Web; WebCreationInformation webCreateInfo = new WebCreationInformation(); webCreateInfo.Description = blogDescription; webCreateInfo.Language = blogLanguage; webCreateInfo.Title = blogTitle; webCreateInfo.Url = blogUrl; webCreateInfo.UseSamePermissionsAsParentSite = blogPermissions; webCreateInfo.WebTemplate = webTemplate; Web oNewWebsite = web.Webs.Add(webCreateInfo); oNewWebsite.QuickLaunchEnabled = true; ctx.Load( oNewWebsite, website => website.ServerRelativeUrl, website => website.Created); ctx.ExecuteQuery(); } } } } }
Notice the changes made on the function. You can play around with it, like adding parameters when accessing the console application. Run the application and check the changes in your SharePoint Server. I find the console application much better to work with if I have a main application that needs to interact with SharePoint(but you can do a UI application too). Next tutorial, I'll give other COM function samples and using the web references. Ka-ciao! ;)
Comments
Post a Comment