SharePointAds TextOnly

Showing posts with label SharePoint Online. Show all posts
Showing posts with label SharePoint Online. Show all posts

Thursday, 16 May 2013

SharePoint Client Object Model : How to change default content type programatically

In this blog I am going to show how to change default content type programatically using the SharePoint client object model. In one of my task assignments I was using custom content type in the document library and to update this new content type as a default content type for the document library.
The top content type is always default content type for all type of SharePoint libraries. So that you have to just change the content type order of library and make your custom content type on the top.
Following is the code method to change the content type order.
Include "using SP = Microsoft.SharePoint.Client;" on the top of your class.

void ChangeContentTypeOrder(SP.ClientContext ctx, SP.List list, string contentTypeName)
{
            SP.ContentTypeCollection currentCTOrder = list.ContentTypes;
            ctx.Load(currentCTOrder);
            ctx.ExecuteQuery();

            IList<SP.ContentTypeId> reverceOrder = new List<SP.ContentTypeId>();
            foreach (SP.ContentType ct in currentCTOrder)
            {
                if (ct.Name.Equals("contentTypeName"))
                {
                    reverceOrder.Add(ct.Id);
                }
            }
            list.RootFolder.UniqueContentTypeOrder = reverceOrder;
            list.RootFolder.Update();
            list.Update();
            ctx.ExecuteQuery();           
}



Where "SP.List list" is the list name and  'string contentTypeName' is the custom content type which you have to make as a default content type

Thursday, 6 December 2012

SharePoint Online: Get web full url


Sometimes you need to get full url of current web. following is the short method which will return you full web url.

public string getWebFullUrl(Web web)
{ 

string webTitle = web.ServerRelativeUrl.Substring(web.ServerRelativeUrl.LastIndexOf("/") + 1);

return web.Context.Url + webTitle + "/";

}



Remember web.ServerRelativeUrl will return only relative url, as show in following table:

Site Collection URL
Site URL
web.ServerRelativeUrl
http://MySharepointsite.com
http://MySharepointsite.com
/
http://MySharepointsite.com
http://MySharepointsite.com/site1
/site1
http://MySharepointsite.com
http://MySharepointsite.com/sites/site1
/sites/site1

Thursday, 29 November 2012

SharePoint 2010: Print List Views Button on Ribbon

After getting lots of emails/replies from my last post SharePoint 2010 : Print Calendar list. I've decided to expand new solution with new functionality where you can add "Print Button" on each type of SharePoint lists, even if it is SharePoint Calendar list,Document libraries, tasks lists or any custom lists.
This feature is developed as a Sandbox Solution and successfully tested on SharePoint 2010, O365 SharePoint Online sites.
Print Button on Document Libraries Ribbon:


Print Button on Lists Ribbon:






Print Button on Calendar Ribbon:





Please have a look at my new codeplex solution to download and install feature in your SharePoint 2010 site.
Download Solution from Codeplex