DocumentIdProvider DocumentIdProvider DocumentIdProvider Class

Definition

Represents the base abstract class for implementing a Document ID generator.

public ref class DocumentIdProvider abstract
public abstract class DocumentIdProvider
Public MustInherit Class DocumentIdProvider
Inheritance
DocumentIdProviderDocumentIdProviderDocumentIdProvider
Derived

Examples

<pre><code>using System;

using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Office.DocumentManagement; using Microsoft.SharePoint;

namespace CustomDocIDProvider { /// &lt;summary&gt; /// This class provides an example of implementing a document ID provider. /// &lt;/summary&gt; /// &lt;remarks&gt; /// The format of ID is "{web Name}@{list Item Guid} is custom ID!" /// &lt;/remarks&gt; public class CustomDocumentIDProvider : DocumentIdProvider { // The format is "&lt;web Name&amp;gt;@&lt;list Item Guid&gt; is custom ID!" private string idFormat = "{0}@{1} is custom ID!";

    public override string[] GetDocumentUrlsById(SPSite site, string documentId)
    {
        string itemUrl = string.Empty;
        // Only proceed if we have the site and document id
        if (site != null &amp;amp;&amp;amp; !string.IsNullOrEmpty(documentId))
        {
            string[] splits = documentId.Split('@', ' ');
            string webName = splits.Length &amp;gt; 0 ? splits[0] : null;
            string itemId = splits.Length &amp;gt; 1 ? splits[1] : null;
            try
            {
                SPWeb web = string.IsNullOrEmpty(webName) ? site.OpenWeb() : site.OpenWeb(webName);
                SPListItem item = null;
                Guid itemGuid = new Guid(itemId);
                // Find the item among the lists on the specified web
                foreach (SPList list in web.Lists)
                {

try { item = list.Items[itemGuid]; } catch { //if it's not in this list, go to the next one continue; } if (item != null) { itemUrl = web.Url + "/"; itemUrl += item.Url; } } } catch (Exception) { /* item not found, return an empty array*/ } }

if (string.IsNullOrEmpty(itemUrl))
{

return null; } else { return new string[] { itemUrl }; } }

    public override string GenerateDocumentId(SPListItem listItem)
    {
        if (listItem == null)
        {
            throw new ArgumentNullException("listItem");
        }
        return string.Format(this.idFormat, listItem.Web.Name, listItem.UniqueId.ToString());
    }

    public override string GetSampleDocumentIdText(SPSite site)
    {
        return string.Format(this.idFormat, "/", "0");
    }

    public override bool DoCustomSearchBeforeDefaultSearch
    {
        get { return false; }
    }
}

}

Remarks

It is highly recommended that the Document ID generator provide IDs that are both unique and readily type-able by a user.

Constructors

DocumentIdProvider() DocumentIdProvider() DocumentIdProvider()

Initializes a new instance of the DocumentIdProvider object.

Properties

DoCustomSearchBeforeDefaultSearch DoCustomSearchBeforeDefaultSearch DoCustomSearchBeforeDefaultSearch

Gets a Boolean value specifying whether the current instance of the provider custom search method (Microsoft.Office.DocumentManagement.DocumentIdProvider.GetDocumentUrlsById) should be called before built-in search is called when the user is trying to locate a document by its DocumentId value.

Methods

GenerateDocumentId(SPListItem) GenerateDocumentId(SPListItem) GenerateDocumentId(SPListItem)

Generates a document ID when provided with a list item parameter that corresponds to a document.

GetDocumentUrlsById(SPSite, String) GetDocumentUrlsById(SPSite, String) GetDocumentUrlsById(SPSite, String)

Implements a custom search method; returns an array of URLs pointing to documents with a specified DocumentId value.

GetSampleDocumentIdText(SPSite) GetSampleDocumentIdText(SPSite) GetSampleDocumentIdText(SPSite)

Returns the default Document ID value that will be initially displayed in the Document ID search web part.

Extension Methods

ToJson(Object) ToJson(Object) ToJson(Object)

Applies to