SharePointAds TextOnly

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

Tuesday, 3 January 2012

SharePoint Client Object Model: CAML query execution using pagination

Below approach is used when user wants to perform pagination based on given parameters. In order to make paging work, you need to get page index and recurring count values from user.
List Items can be retrive in result and user can specify PageIndex and RecCount values which will be used for resulting certain number of values.


If your list is having more than 1 million and user requested only for list items in the rage of 100-200 then it is not good practice to get all list item collection. To avoid to load all list items collection you need to get required list item from CAML and using Paging. The logic is :

  1. Calculate skip value
  2. Assign skip values to ListItemCollectionPosition PagingInfo e.g. Paged=TRUE&p_ID=SKIP_NUMBER”
  3. Pass ListItemCollectionPosition value to CAML query
  4. Apply RowLimit value to CAML query

Suppose if you are trying to get list items from 100 to 200 then assign PageIndex =2 and recCount =100 into the following method.
//Add client
using SP = Microsoft.SharePoint.Client;

public void getItems(int pageIndex, int recCount)
{
SP.ClientContext ctx = getClientContext(); //authenticate client context
                                          // first Authentication post for more details

if (ctx != null)
{
              int iSkip = pageIndex * recCount - recCount;
              SP.List list = ctx.Web.Lists.GetByTitle("Your LIst Name"); // replace with your list name
              ListItemCollectionPosition itemPosition = new ListItemCollectionPosition();
              itemPosition.PagingInfo = string.Format("Paged=TRUE&p_ID={0}",iSkip);
              CamlQuery camlQuery = new CamlQuery();
              camlQuery.ListItemCollectionPosition = itemPosition;

              camlQuery.ViewXml = @"<View><ViewFields>
                                    <FieldRef Name='ID'/>
                                    <FieldRef Name='Title'/>
                                    </ViewFields><RowLimit>" + recCount + @"</RowLimit>
                                    </View>";
                  
SP.ListItemCollection listItems = list.GetItems(camlQuery);
              ctx.Load(listItems);
              ctx.ExecuteQuery();

              foreach (SP.ListItem listItem in listItems)
              {
//Do forward with listItem["ID"].ToString() and  listItem["Name"].ToString()
              }
}
}


Please have a look at Authentication post for more details about SharePoint Client object model authentication.