Find duplicate items in SharePoint

By Namwar Rizvi - Last updated: Wednesday, December 22, 2010

There are some situations when two different users of SharePoint upload same document with two different names. This mostly happens when both of them do not know that someone else has already uploaded same document earlier. SharePoint displays the “[View duplicates]” link when it finds duplicate items for a given search result.

On clicking the “[View duplicates]” link, you will notice that SharePoint searches the duplicate items by creating a keyword query of “duplicate:Full Document Url

To make our life easier, I have created a Feature which will add a context menu item in ECB and will allow user to directly find duplicates for any item, from the context menu, without first going to the search page.

To get the idea, here is a snapshot of what you will get once our feature is activate:

ECB View Duplicates

Edit Control Block Menu for View Duplicates Option

User will just click on View Duplicates option and will get all the duplicate documents for the selected document.


  1. Create a folder named ViewDuplicates under FEATURES folder of your SharePoint installation.
  2. Create a file called Feature.xml under ViewDuplicates folder.
  3. Paste the following code in Feature.xml:
  4. <?xml version="1.0" encoding="utf-8"?>
    <Feature  Id="960206DD-D07E-4b64-AD8A-3E48D7527060"
              Title="View Duplicates"
              Description="This feature allows user to view duplicate copies of the selected document."
        <ElementManifest Location="elements.xml"/>
  5. Create a file called Elements.xml under ViewDuplicates folder.
  6. Paste the following code in Element.xml:
  7. <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="">
      <!-- Per Item Dropdown (ECB) Link -->
      <CustomAction Id="ViewDuplicates.ECBItemMenu"
        Title="View Duplicates">
        <UrlAction Url="javascript:function findDuplicates(){var itemUrl='{ItemUrl}'; var fullUrl=location.protocol+'//';  window.location.href='/Search/results.aspx?k=duplicates:&quot;'+ fullUrl + '&quot;'};findDuplicates();"/>
  8. Install the feature by executing stsadm -o installfeature -name ViewDuplicates
  9. Activate the feature by executing stsadm -o activatefeature -name ViewDuplicates -url <YourSiteCollectionUrl>. Replace <YourSiteCollectionUrl> by the url of your site collection.
  10. Now, you will get “View Duplicates” option with every document. Click it and Enjoy!
Filed in Code, Feature, How To, Information, Search, Solutions, SP2010 • Tags: , , , , , , , ,

Download wsp solution file from SharePoint Farm

By Namwar Rizvi - Last updated: Sunday, October 10, 2010

Some times you need to download the solution file from SharePoint Farm. SharePoint user interface does not provide any functionality to achieve it .  Don’t worry, you can extract the solution file from SharePoint Farm by using object model. Here is a simple function to extract your target solution file from SharePoint.

/// <summary>
/// Downloads the solution file from SharePoint Farm.
/// </summary>
/// <param name="targetSolutionName">Name of the target solution.</param>
/// <param name="pathToSave">The path to save.</param>
private static void DownloadSolutionFile(string targetSolutionName, string pathToSave)
 	if (!String.IsNullOrEmpty(targetSolutionName) &amp;&amp; !String.IsNullOrEmpty(pathToSave))
		//Search for target solution
		var solution = (from s in SPFarm.Local.Solutions where s.Name == targetSolutionName select s).FirstOrDefault();

		if (solution != null)
			//target solution found, extract the solution file and save it
			SPPersistedFile solutionFile = solution.SolutionFile;
			solutionFile.SaveAs(pathToSave + solutionFile.Name);
Filed in Administration, C#, Code, How To, Management, Object Model, Solutions • Tags: , , , ,

Solution for “HRESULT: 0x80040E60” Error in SharePoint Search

By Namwar Rizvi - Last updated: Wednesday, September 22, 2010

If you are getting “Exception from HRESULT: 0x80040E60” error while executing FullTextSqlQuery then most probably it is due to your Order By column.  Make sure you use that property in Order By clause which is configured to have a single value in Manage Property configuration screen.

Make sure you have selected “Include values from a single crawled property based on the order specified option otherwise; you can not sort results by that property.

The reason behind this restriction is that logically sorting can be performed on objects who have single value which can be compared to other object’s value and then the precedence can be determined. On the other hand, if objects have multiple values then their precedence can not be determined.

Filed in Debugging, How To, Search, Troubleshooting • Tags: , , , ,

What is Sharepoint\System account?

By Namwar Rizvi - Last updated: Sunday, September 5, 2010

Many people ask this question that what is SharePoint\System account? So here is the answer:

  1. SHAREPOINT\System account is the same account used by application pool of your SharePoint web application in IIS at the time of creation/extension of respective web application.
  2. This is the account which is used when you run your code in under elevated privileges by SPSecurity.RunWithElevatedPrivileges.
  3. When you create/extend a web application in SharePoint and specify an Application Pool then the identity (Network Account) used by that Application pool becomes the SHAREPOINT\System account.
  4. It is highly recommended that end user should not be allowed to use this account to avoid unexpected errors.
  5. If you change the identity of App Pool account after creating/extending the SharePoint web application, the new account will not become the SHAREPOINT\System.
Filed in Information, SP2010 • Tags: , , ,

Solution for JavaScript Error on Search Results Page in SharePoint

By Namwar Rizvi - Last updated: Tuesday, August 24, 2010

One of my clients reported that they have started getting “Object Expected” javascript error whenever they click on any link in Search Results of SharePoint. This was quite odd as the search results page was the out of the box search result page without any customization (…well up till now 😉 )…

After investigating the issue, I found out that client had deleted the “Search Box” web part from the search results page as they don’t want user to search again from the results page and you know what? “Object expected” error started popping up as soon as client removed the “Search Box” web part.

The reason is as follows:

  1. SharePoint records the user clicks on search results link.
  2. Recording of clicks utilizes a JavaScript function called “SendSoap” to asynchronously record the click.
  3. SendSoap function is defined in Search.js file located at /_layouts/ 1033 folder.
  4. Search Box web part includes this file on search results page.
  5. Search Core Results web part assumes that Search.js file will always be available and attaches the call to SendSoap on Search Result links.
  6. Deleting the Search Box web part will remove the reference to Search.js and as a result you will start getting the Object expected error whenever you click any link on results page.


  1. If you really don’t want Search Box web part on your search result page then mark it hidden instead of deleting it. In this way, you will have the reference of Search.js in your search page.   OR
  2. Include the reference to Search.js manually either by CEWP or any other means, you feel appropriate.
Filed in Errors, Search, Solutions, Troubleshooting • Tags: , , ,

Solution for “Invalid URL value. A URL field contains invalid data. Please check the value and try again”

By Namwar Rizvi - Last updated: Friday, August 13, 2010

If you try to update field of type SPUrlField in SPListItem, you may encounter “Invalid URL value. A URL field contains invalid data. Please check the value and try again” error. This error can occur due to several reasons. I found a good description in a Microsoft SharePoint forums by Somak Bhattacharyya . I found it quite useful and  hope it will help you to fix this issue:

  1. The URL that you are creating doesn’t exceed 255 characters. This is because the Hyperlink type column in SharePoint does not accept more than 255 characters as an URL. This is what had happened personally to me . Had a pretty tough time figuring it out myself.
  2. Check that your URL is well-formed. To check this, try to browse the URL, that you are generating, in IE and see whether it points to your desired target. Just Copy paste the URL generated to the Address bar of IE and press enter. Ideally this should open the page you are trying to link to. If it is not then you instantly know that what you are generating is wrong. Correct it!
    NB: You may get the URL generated runtime from inside your Code by logging it into the Event Log or just by redirecting it to a text file or invoking IE by passing the URL generated as a parameter.
  3. If you are directly assigning the value to the column like:
    Item[“”] = “,”, then check that you are not missing the after the comma.
  4. The best possible way to do it I feel is in this way:
    SPFieldUrlValue yourURL = new SPFieldUrlValue();
    yourURL.Url = "";     // For example:
    yourURL.Url = yourURL.Url.Replace(" ", "%20");    // This is however optional.
    yourURL.Description = ""; // eg:Microsoft.
Filed in Debugging, Errors, How To • Tags: , , ,

How to hide User Name from SharePoint Lists

By Namwar Rizvi - Last updated: Thursday, August 12, 2010

Sometimes we need to hide the Created By, Modified By user names in display pages of SharePoint. This requirement mostly come in Surveys where you do not want to show who answered the survey.

You can hide this information from being displayed by setting ShowUser property of SPList object to false.

Following is a code example of doing it:

using (SPSite s = new SPSite("Your Site URL"))
using (SPWeb w = s.OpenWeb("Your Web URL"))
SPList lib = w.Lists["Name of Your Target SharePoint List"];
lib.ShowUser = false;

After running the above code, if you check the properties of an item in your list e.g. document library, you will get the page similar to following

Filed in Code, Customization, Information, Tips, Troubleshooting • Tags: , , ,

How to solve “Code blocks are not allowed in this file” error?

By Namwar Rizvi - Last updated: Monday, August 9, 2010


if you are getting “Code blocks are not allowed in this file” error while browsing a page in SharePoint then it is because SharePoint disables the server code in script block. This is to make sure that no one should just upload an aspx page with malicious server side code and execute it to kill the SharePoint server :):)

OK, got it….now tell me how to allow server code in a specific page?

Here you go, just add following PageParserPath nodes under PageParserPaths node.  Refer below for an example:

        <!-- Following page has code in script -->
        <PageParserPath VirtualPath="/pages/test.aspx" CompilationMode="Always" AllowServerSideScript="true" />

Filed in Debugging, Errors • Tags: ,

What is ECM and how it relates to SharePoint?

By Namwar Rizvi - Last updated: Thursday, August 5, 2010

There are lot of confusions surrounding the terms ECM (Enterprise Content Management System). Just Google it and you will find thousands of definitions but IMHO they all will confuse you further 🙂

Being a SharePoint technologist, you must have a fairly good idea about these terms and what they actually mean to any organization. To understand the ECM concept, some fundamental points needs to be understood:

Having these points in our mind, here is what ECM is

An ECM enables you to manage information by providing relevant tools and technologies such as software for file management from FileCenter, as one example.

OK, OK,….what SharePoint is doing with ECM?

SharePoint is providing you tools and technologies to manage your enterprise information.

Tools? Where are these tools? Here they are:

  1. Document Library and document management through web browser.
  2. Content creation, retrieval through Office Applications like Word, Excel, Outlook etc.
  3. Use Visio for process/status monitoring.
  4. BI Dashboards for enterprise data.
  5. Seamless browsing, editing of information of external systems by BCS etc

Hmmm… ok but am still confused about technologies… Technologies are:

  1. Workflows to route the documents as per company requirements.
  2. Security Framework to securely authenticate and authorize the user access to information.
  3. Content Retention policy framework to safely dispose contents when they are no longer needed.
  4. Record Management to easily locate the content.
  5. Version Management to track changes.
  6. Auditing to track the actions performed in a given time period.
  7. APIs to enable third party applications to explore and manage information in a secure, traceable and manageable manner.

Good…I think I got some idea…but am still confused….just kidding :):)

Filed in Concepts, Information • Tags: , , ,

SharePoint 2010 Administration Toolkit V1 is released

By Namwar Rizvi - Last updated: Monday, August 2, 2010

Microsoft has released the SharePoint 2010 Administration Toolkit V1. This toolkit enables administrators to :

I need more information before I can decide…..

Detailed documentation is available at:

SharePoint Foundation 2010:

SharePoint Server 2010:

OK, enough talk…show me the money! .. where is the download link?

The toolkit can be downloaded from here

Filed in Administration, Information, SP2010, Troubleshooting • Tags: , , ,