Learn SharePoint With Questions                                                   Question on MOSS Administration
                                                                                                                                                                                                                                                                                                         Beginner Test / Developer Test

Monday, 23 November 2009

Assigning Document ID to the Documents in SharePoint 2010

I was working on a SharePoint 2010 site which was build on Team Site Template. I was not able to find the Doument Ids for the document uploaded into the Document Library in this site. Even the Document ID column was not appearing in the document libarary. On further investigation I found that we need to enable the Document ID Feature to use the Document ID's in the library. If we use a Document Center template to create a site collection the Document ID feature is enabled by default. To enable Document ID feature go to Site Actions --> Site Settings --> Under Site Collection Administration --> Site Collection Feature


and enable the Document ID Service Feature. Once this feature is activated the Document ID column will start to appear:


I have uploaded couple of documents in the Document in the document library. Still these documents does not have any Document Id's associated even after enabling the Document ID Service and it shows blank.


If I upload a new document it was getting associated with a Document ID:



Now the question is how to get the Document Id's for these existing documents. On some investigation I found there are 2 jobs which runs on a daily basis. These job are
1. Document ID enable/disable job: Work item that propagates content type changes across all sites when the Document ID feature is reconfigured.
2. Document ID assignment job: Work item that assigns Document ID to all items in the site collection.
Now I executed Document ID assignment Job from the Central Admin and my all the documents in the Document Library got a Document ID :)


Since this job is scheduled to run daily it means if enable the Document ID Service all the existing documents will get a Document ID when this job executes.

There is also another feature with Document ID that we can change the characters in the Document ID. To do this go to Site Actions --> Site Settings --> Under Site Collection Administration --> Document ID Settings



I have modified the string here to start with ABCD and all my new documents are getting the Document ID starting with ABCD:

We can also select to change all the existing documents to be assigned with this customized Document ID's. This also is taken care by the Document ID assignment job. I have exextued this job again and it has changed all the documents ID's in the document library.

Friday, 20 November 2009

Error while working with PowerShell

I was trying to put my hands around PowerShell and I was encounring a strange error. I was running one cmdlet Get-SPWebApplication in Windows Server 2008 Server and it was throwing this error:
"Cannot access the local farm. Verify that the local farm is properly configured, currently available, and that you have the appropriate permissions to access the database before trying again."


I tried all the cmdlets but the same error keep coming. After some more investigation I found that the solution and it was that the PowerShall needs to be executed as Administrator. While running powershell it shows 2 option:


If we just click the open it will open a PowerShell window and this message will come:


and all the cmdlets will show the error message as shown. To run the PowerShell scripts we should use the second option of running as Administrator.

Thursday, 19 November 2009

Finding the size of Document Library using SharePoint Object Model

I was working on a SharePoint site where lot of document libraries were there. We had a task to get the size of all these document library. We can do this using the following Object Model Code:
using (SPSite testsite = new SPSite("http://localhost")) 
{ 
       DataTable datatbl; 
       datatbl = testsite.StorageManagementInformation( 
       SPSite.StorageManagementInformationType.DocumentLibrary,  
       SPSite.StorageManagementSortOrder.Decreasing, 
       SPSite.StorageManagementSortedOn.Size, 100); 
       foreach (DataRow drow in datatbl.Rows) 
       { 
          foreach (DataColumn column in datatbl.Columns) 
          MessageBox.Show("Doc Lib Name :" + drow["Title"].ToString() + "  Size (bytes): " + drow["Size"].ToString()); 
       } 
}