Friday, January 27, 2012

How Foundation Search Shows Results

To understand better how search works see the image below. Lets assume we have three site collections with different number of webs in each site collection.

Now if we do search for "Mydoc" file at different site levels we will get different results. 

If search is performed at Top Level Site Collection (S1): Search will be performed at each site collection level and each web.We will get results from all site collections and all webs.

If search is performed at W1: We will get results from W1 and W1a

If search is performed at W2: We will get result only from W2

If search is performed at Site collection 2(S2): We will get results from W3 and W4.

If search is performed at W3: We will get results from W3.

Similarly if we perform search at Site Collection 3(S3): We will get results from only W5. 

If you have noticed in above only Top level site collection returns results from all sites and webs. Where as from all other locations results are returned only from that location and down the tree.

Now the question arises why Top level site collection behaves different from all other levels?
If you see URL for search results at top level site collection it will look something like:

There are two parameters k=MyDoc and u=http%3A%2F%2Fanmol, this means we are doing a search for MyDoc and return all documents that start with http://anmol

As every site collection and every web starts with this URL so we will get results from all locations when search is performed at top level.

Thursday, January 26, 2012

SharePoint Configuring Foundation Search

Configure Foundation Search
  • Open Central Administration
  • Go to System Settings > Manage Service on Server
  • Scroll down to bottom and click start against "SharePoint Foundation Search"
  • Service Account: Please specify managed account
  • Content Access Account: This should be an account dedicated only for search.
  • Search Database: Specify the Database Server and Database Name.
    Specify any Fail over server if you are using any.
  • Indexing Schedule: Here you need to specify proper schedule as per you requirement. If you are not sure then leave default settings as it is.
  • Click Start. It will take few minutes to start up the service.
Next Step is associate Content Database with Search Service.
  • Go to Application Management 
  • Under "Databases" > "Manage Content Databases"
  • Click on link of the content database.
  • For Search Server select the configured search server from drop down.
  • Click Ok. You need to repeat these steps for all content databases.
Remember you can search only after the indexer is run. It will run according to the scheduler you specified. If you want to run it immediately then
  • Go to Monitoring > Review Job definitions
  • Scroll down to "SharePoint Foundation Search Refresh", click on link.
  • Click on "Run Now" button.
or you can use stsadm command
  • stsadm -o spservice -action FullCrawlStart

Sunday, January 22, 2012

SharePoint 2010 Document Library Upload Issues

Issue 1:
Can't upload more than 100 documents at a one time in SharePoint 2010 Library.

Open Library in Explorer View. This way you can upload as many as documents as you like.

Issue 2:
Can't upload documents more than some MB's size


  • Open Central Administration
  • Go to Application Management > Manage Web applications
  • Select Web application and click "General Settings"
  • Scroll down to modal window and change "Maximum Upload Size". You can set this to maximum of 2GB.
  • You may encounter "Security Validation error if upload is taking time more than 30 mins. To resolve this issue. Scroll up and change "Security validation expires"

Issue 3:
Upload Multiple Documents link is greyed out.

Solution 1
This will be greyed out if you have opened the site in Mozilla Firefox. Open site in Internet Explorer and it will be fine.

Solution 2
This is actually client integration component  and can be available if office 2010 client installed. First time you navigate to library you will be asked for an ActiveX Control. You need to install that and everything will work fine.

Monday, January 16, 2012

SharePoint 2010 Custom Document ID Provider

Document ID in another cool feature in SharePoint 2010. It actally assigns a unique identification number to Document in site collection. In order to make it available in your site collection you need to activate feature "Document ID Service".

After you activate this feature you will get another setting "Document ID Settings" under Site Collection Administration. Here you can specify the prefix for the generated Document ID's.

 Below settings will open on click
There could be a situation arise where you are not happy with Document ID format. For example you have two sites "Admin" and "Account" under site collection. You want some naming convention for Document ID in such a way that you can easily found the document location. With default "Document ID" its not possible. To get this you need to create your own Custom Document ID Provider.

Steps to create custom Document ID Provider

Open Visual Studio 2010.

Go to File => New => Project.

Select Empty SharePoint Project template from the installed templates.

Enter the Name "DocumentIDHelper" and click Ok.

Right click on the solution and click on Add a new item.

Select the Class template from the installed template.

Enter the Name as SPDIDProvider.cs and click Ok.
Add the following references to your project
Add the following namespaces in class file

Using Microsoft.SharePoint;
Using Microsoft.Office.DocumentManagement;

The new class needs to be derived from "DocumentIdProvider". DocumentIdProvider contains three abstract methods and one abstract property.

Method 1: GenerateDocumentIdThis method is used to generate Custom Document ID. This method takes one parameters that is of type SPListItem and this method return generated Document ID as string.

Method 2: GetDocumentUrlsById
This method is used to return the url of the document based on Document ID, This method takes two parameters SPSite and string (i.e Document ID). This is helpful

incase we need to search the document and document is still not indexed. If we dont want to return any url we can return empty string as
return new string[] { };

Method 3: GetSampleDocumentIdTextThis is shown as default value in Document ID search webpart.
Property 1: DoCustomSearchBeforeDefaultSearch
If returns true then It will call the GetDocumentUrlsById method before search
Id returns False then It will use SharePoint Search before custom methods

Complete code for SPDIDProvider.cs class

public override string GenerateDocumentId(SPListItem listItem)
                string webname = "Root";

                //If site is not root web then get web name otherwise use web name as Root
                if (!listItem.Web.IsRootWeb)
                    webname = listItem.Web.Name;

                string documentID = webname + "-" + listItem.ParentList.RootFolder.Name + "-ID" + listItem.ID;
                return documentID;
            catch (Exception ex)
            return "";

        public override string[] GetDocumentUrlsById(SPSite site, string documentId)
            return new string[] { };

        public override string GetSampleDocumentIdText(SPSite site)
            return "Web-Library-ID1";

        public override bool DoCustomSearchBeforeDefaultSearch
                return false;
Now next step is to set Custom Document ID Provider as default Provider.

For this add new Feature "CustomDocumentIDGenerator" to your Project. Right Click your feature and Add Event Receiver.
 On FeatureActivated Set our custom Provider as Default document ID Provider

      public override void FeatureActivated(SPFeatureReceiverProperties properties)
            SPDIDProvider iProvider = new SPDIDProvider();
            DocumentId.SetProvider((SPSite)properties.Feature.Parent, iProvider);

On Feature deactivating set default Document Provider
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)

Next step is deployment. After deployment again go to Document ID Settings. And you will see screen as below
See highlighted text "A custom Document ID provider has been configured for the site collection"

Now try to upload document to different sites. You will see diffrent Document IDs format in diffrent webs.

Document ID in Admin Web
Document ID in Account Web 

Popular Posts