Subscribe:

Labels

Thursday, February 9, 2012

Document ID in SharePoint 2010

SharePoint 2010 includes a new Site Collection scoped Feature called the Document ID Service.  As most of you might be aware that in a traditional ECM [Enterprise Content Management] application each content object has its own unique ID, which is used by that object throughout its lifetime in the ECM system, no matter where the file was placed in the system. Once enabled all your documents within a Site Collection will have a unique ID and can be located using the ID no matter where the file is located in your Site Collection.
To enable the Document ID Feature
1. Go to Site Settings > Site Collection Features and Activate the Document ID Service.

2. Or you can use the following SharePoint 2010 Management Shell cmdlet to Activate the Document ID Service.
Enable-SPFeature -id docid -url <site collection url>
After Activating the Feature you can find the “Document ID settings” under Site Collection Administration

3. To customize the Document ID and apply Document ID to all existing Documents in the Site Collection. Go to Site Settings > Document ID Settings and provide the String with which the Document ID will begin. I have provided SP2010 for this example. Click Ok.
You might see this message, "Configuration of the Document ID feature is scheduled to be completed by an automated process." as highlighted in the image:
This message is shown because the timer job called Document ID enable/disable job has been activated. 
Run the Document ID assignment job under Central Administration > Monitoring > Review Job Definitions Once the job completes at the scheduled time, the message will go away or else you may run the timer job and put it to completion forcibly by clicking "Run Now". Or you can run the following SharePoint 2010 Management Shell cmdlet to trigger the same.
Start-SPTimerJob -Identity DocIdAssignment


Now if you go to your document properties you should see, it has a new property called Document ID followed by a Unique ID for that document

4. The above document now has a unique ID and we can use the following link to locate the document no matter where the document is in the Site Collection
http://SP2010:1234/_layouts/DocIdRedir.aspx?ID=SP2010-1-1

Wednesday, February 8, 2012

List Throttling in Sharepoint2010

SharePoint 2010 has  number of new features centered around working with large lists.  A new feature is incorporated into SPS 2010 for putting limit on the amount of data to be retrieved from the servers. The feature is called List Throttling.
SP2010 can support up to 50 million items in a list now, but you don’t obviously want to return all of those in a single query.  To aid with this, SP2010 introduces list throttling settings (configured at the web application level), that allow you to specify how many items a user can query before the throttle kicks in and aborts the query.  At the time of writing, these limits are set to 5,000 for normal users and 20,000 for super users.  Remember you can change these settings if you so choose.  I’ll be curious to see what numbers people actually end up running with.  This applies to anything that queries the list whether its through the SharePoint UI or from your own custom code.  If the user submits a query that is too large, the SharePoint UI will tell the user that the query is too big and they need to filter it.
List throttling is managed through web application. Click on Application Management --> Manage Web Applications.  Select the web application you want to configure list throttling, then in the ribbon click on the General Settings drop down and select the Resource Throttling item. Below figure shows how to enable list throttling in a web application.

In order to retrieve information using the object model in order to retrieve up to the number of items specified in the List query size threshold for auditors and administrators property, there is a property you need to set in your query object. 
The property is called QueryThrottleMode and it applies to the SPQuery andSPSiteDataQuery classes.  You simply set this property to override and then use your class instance to query. 
using (SPSite oSite = new SPSite("http://sp2010:1234")) 
{
using (SPWeb oWeb = oSite.RootWeb)
{
SPList oList = oWeb.Lists["Test List"];

SPQuery oQuery = new SPQuery();
oQuery.QueryThrottleMode = SPQueryThrottleOption.Override;


            SPListItemCollection oListColl = oList.GetItems(oQuery);
            //Your custom logic here for processed data
}
}
Enhanced by Zemanta

SPDisposeCheck for SharePoint development


SPDisposeCheck is  tool that helps to developers and administrators check the custom SharePoint solutions that use the SharePoint Object Model helping measure against known Microsoft dispose best practices. This tool may not show all memory leaks in your code and may produce false positives which need further review by subject matter experts.

The SPDisposeCheck updated tool remains a standalone command line utility and have been added to a Visual Studio 2008/2010 IDE Add-In which calls out to the SPDisposeCheck.  This Add-In was originally presented at the SPC 2009 and is now available publically.  In addition this version has been tested with both WSS 3.0 + MOSS 2007 and SharePoint 2010 (Foundation and Server) environments.

Finally, it is encouraged you to run the updated SPDisposeCheck tool on all customized SharePoint projects to help identify areas in code which may lead to memory pressure and server stability issues.  As a best practice you should consider adding this tool to your SharePoint software development life cycle build process and review its output with a subject matter expert on a regular interval.
Enhanced by Zemanta

sharepoint long Operation example using object model code

.  In the following example I have use LongOperation using sharepoint Splongoperation class. I have created a custom Web Part that has a button on it to create a site where I need perform some custom actions.

As a SharePoint Developer, you can wrap your lengthy operations code with the SPLongOperation to display the spinning wheel processing screen whenever you are executing long duration code-block to improve the user experience. After invoking SPLongOperation object, you can start and stop the long operation using Begin() and End() methods. Alternatively, you can use the LeadingHTML and TrainingHTML properties to customize the message on the processing screen.
protected void btnProvisionSites_Click(object sender, EventArgs e)
{
    //Long Operation Code
    using (SPLongOperation longOperation = new SPLongOperation(this.Page))
    {
        //Custom Messages on the Spinning Wheel Screen
        longOperation.LeadingHTML = "Provisioning Sites";
        longOperation.TrailingHTML = "Please wait while the sites are being provisioned.";
        //Start the long operation
        longOperation.Begin();
        //Your Long Operation Code Goes Here...
        // e.g. Site provisioning code
        //End the long operation
        string redirectURL = SPContext.Current.Web.Url;
        longOperation.End(redirectURL);
    }
}
Enhanced by Zemanta

Wednesday, January 18, 2012

Programmatically Create a Site from Custom Site Template in SharePoint 2010


Here is the code snippet to create a Site using a Custom Site Template in SharePoint 2010.
      
using (SPSite site = new SPSite("http://sp2010:1234/"))
      {
                    using (SPWeb newWeb = site.OpenWeb())
                    {                         
                        newWeb.AllowUnsafeUpdates = true;                      
                        SPWebCollection subsites = newWeb.Webs;
                        SPWeb newSubWeb = subsites.Add("Site url", " Site name ", "Site description", 1033, {Name of the Site Template}, true, false);
                        newWeb.Update();
                    }
                }


 for eg: {Name of the Site Template} --> "{9D26F676-B943-451B-BED4-A8657A9C0FDF}#1InternalProject"


To get the custom Site Template GUID and Site Template Name you can use the below code in SharePoint 2010. If the Template is in Solution Gallery. 
SPWebTemplateCollection templates = newWeb.GetAvailableWebTemplates(1033, true);
                        foreach (SPWebTemplate template in templates)
                        {
                           lblTemplate.Text=  template.Name;
                        }