Tuesday, August 31, 2010

SPQuery Returns All of the Items

During a development project, calling SPQuery returned all items from list! Looks like it just ignored the filters we applied.

SPList list = new SPSite("http://MySharePointSite").OpenWeb().Lists[listName];

SPQuery query = new SPQuery();

query.Query = "<Query><Where><Eq><FieldRef Name="Title" /><Value Type="Text">Test</Value></Eq></Where></Query>";

SPListItemCollection items = list.GetItems(query);


Fix is: This above code returns all items in the list, but if you remove the <Query> tag all works fine:

SPList list = new
SPSite("http://MySharePointSite").OpenWeb().Lists[listName];


SPQuery query = new SPQuery();

query.Query = "<Query><Where><Eq><FieldRef Name="Title" /><Value Type="Text">Test</Value></Eq></Where></Query>"; 

SPListItemCollection items = list.GetItems(query);

Remember, Query XML is case sensitive! So <Where> is not equal to <where>


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, August 30, 2010

Change PDF Icon in SharePoint

By default, SharePoint does not include PDF document file type icon. So we need to do the below changes to display the PDF icon for PDF files in our SharePoint environment. Here is how we can add PDF icon in SharePoint 2010:
  1. Download an appropriate icon for pdf document type. you can download pdf icon for SharePoint from http://www.adobe.com/misc/linking.html 
  2. Copy the downloaded PDF icon to "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\template\images" (Dont forget to set the read, Read & Execute permissions to "Domain users" to that PDF icon file!)
  3. Open the docicon.xml from C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\template\xml\docicon.xml
  4. Add an entry under     <ByExtension> node:
   <Mapping Key="pdf" Value="pdficon_small.png"/>

Once done, you will get the PDF icon in SharePoint library as in below screen: SharePoint 2010 displays PDF icon.
Display PDF Icon in SharePoint

Same method applies, If you want to provide support for custom file type icons. Refer: How to Add Custom File Type Icons in SharePoint


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


You might also like:

Related Posts Plugin for WordPress, Blogger...