08 April 2009

PDF icon not displayed in the SharePoint search results.

Follow the steps below to enable the display of pdf icon in the SharePoint search result.

1. Search the internet for a pdf image, preferably a jpg or gif of size 16X16. You can use the image below as well.

2. Copy the pdf image into the images in the below location

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\IMAGES

3. Find in the DOCICON.xml file present in the below location

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\XML

4. Add the values <mapping key="pdf" value="yourimagefilename"> in the <byextension></byextension> section.

5. Reset IIS.

6. Search for any pdf file on the portal and the image should be visible now.

24 March 2009

SharePoint Tool : U2U CAML Query Builder

CAML stands for Collaborative Application Markup Language. It is an XML based query language that is used to retrieve information from a SharePoint site. Writing CAML queries can be a real task. Searching the net for any documentation returns bits and pieces of information.
CAML Query Builder tool saves the headache associated with writing CAML queries (especially if one is new to it).

The downloadable links are available here.

CAML Query Builder Tool for 2007

CAML Query Builder Tool for 2003

Note: The XML generated by the tool is wrapped in <Query></Query> tag. Some of the objects in SharePoint that take CAML query as input require that the <Query></Query> tag be omitted. Since it doesn’t return an error, it can be difficult to debug sometimes.

18 March 2009

MOSS 2007 tip: RunWithElevatedPrivileges to update a list in SharePoint

Recently we had a requirement where we had to create a folder in a document library whenever a listitem was added in another list. Although this seemed simple and the code worked properly in development environment, we started getting errors when we had the application running in production. The reason was that a few users had add rights on one of the lists but had only view rights on the document library in which the folder had to be created.

SharePoint’s SPSecurity has a wonderful but dangerous (if not used properly) method which provides a solution to the above problem.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx gives a detailed description of the method. Point to note here is that the SPSite or SPWeb object needs to be recreated to execute under full control rights. Remember to create the object with the C# using construct so that the object is disposed once the required task is completed.

Feature '00bfea71-e717-4e80-aa17-d0c71b360101' for list template '101' is not installed in this farm

Feature '00bfea71-e717-4e80-aa17-d0c71b360101' for list template '101' is not installed in this farm.  The operation could not be completed.

If you are one of those who have come across this error, then you are not alone. And I know the feeling that goes with it as you see all your web pages throw up random errors which you could make very less meaning of.

I came across this error when I was uninstalling a custom feature that I had written for a site. As complex as the error seemed to be, the solution couldn’t have been much simpler. SharePoint had somehow uninstalled the default Document Library template while uninstalling my custom feature. The solution to this is to re-install the Document Library template which is implemented as a feature in SharePoint.

You should find the feature.xml file in the “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES\DocumentLibrary” location.

Run the stsadm command as shown below

Stsadm –o installfeature –filename C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES\DocumentLibrary\feature.xml

17 March 2009

Creating folders within an SPList : MOSS 2007

SharePoint allows creation of folders within a list. This has a lot of advantages some of which are mentioned below.

  • Segregation of related list items.
  • Easy management of List operations like add, delete, update and search.
  • Easy management of permissions as related items can be assigned permissions at the folder level.
Usually, there is a requirement of creating these folders dynamically using code.

SPSite oSPSite = new SPSite("http://mysharepointsite");
SPWeb oSPWeb= oSPSite.OpenWeb("mywebsite");

SPList oSPList = oSPWeb.Lists["Country"];
SPListItem oSPListItem = oSPList.Folders.Add(oSPList.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, null);

oSPListItem["Name"] = "France";

The first parameter of Folders.Add method mentions the level at which the item has to be created. In the above example we specified that the folder should be created at the root level within the list.
The second parameter mentions the type of list item to be created.

12 March 2009

Get Listitems from within folders in a SharePoint List recursively using SPQuery

Usually, a list defined in SharePoint consists of listitems that are stored within folders. One requirement while searching for data using SPQuery object is to get all listitems that match the specified criteria irrespective of where the data is stored in the folder hierarchy of the list.

Consider a list named “Students” that holds records of all students studying at a university. The records are stored within different folders. To get a list of students whose FirstName is “David”, the query would be

SPQuery query = new SPQuery();
query.ViewAttributes = "Scope="Recursive"";
query.Query = "<Where><Eq><FieldRef Name='FirstName'/><Value

The important thing to note here would be the use of the ViewAttributes property of the SPQuery object. The value of ViewAttribues property mentioned above instructs the SPQuery object to search recursively within all folders in the list.

10 March 2009

Using VS2008 to develop SharePoint workflows on 64-bit Windows Operating system

One frustrating issue that we faced was that VS2008 cannot be used to develop SharePoint workflows on 64-bit Windows systems. Selecting any of the SharePoint workflow templates from the menu returns an “Object reference not set to an instance of an object” error. After searching a lot, I came across a bug reported by someone who faced the same problem.


The reason mentioned for this bug by Microsoft is a lack of resource and an assurance that it will be solved in the future releases.

Since we already had the setup on a 64-bit machine, the workaround we used was to download sample workflow examples from the internet and modify them according to our requirements.