DocumentIdProvider-Klasse

Stellt die abstrakte Basisklasse für die Implementierung eines Dokument-ID-Generators dar.

Vererbungshierarchie

System.Object
  Microsoft.Office.DocumentManagement.DocumentIdProvider

Namespace:  Microsoft.Office.DocumentManagement
Assembly:  Microsoft.Office.DocumentManagement (in Microsoft.Office.DocumentManagement.dll)

Syntax

'Declaration
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public MustInherit Class DocumentIdProvider
'Usage
Dim instance As DocumentIdProvider
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public abstract class DocumentIdProvider

Hinweise

Es wird dringend empfohlen der Dokument-ID-Generator IDs bereitstellen, die eindeutig und leicht Typ kann von einem Benutzer.

Beispiele

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

namespace CustomDocIDProvider
{
    /// <summary>
    /// This class provides an example of implementing a document ID provider.
    /// </summary>
    /// <remarks>
    /// The format of ID is "{web Name}@{list Item Guid} is custom ID!"
    /// </remarks>
    public class CustomDocumentIDProvider : DocumentIdProvider
    {
        // The format is "<web Name>@<list Item Guid> 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 && !string.IsNullOrEmpty(documentId))
            {
                string[] splits = documentId.Split('@', ' ');
                string webName = splits.Length > 0 ? splits[0] : null;
                string itemId = splits.Length > 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; }
        }
    }
}

Threadsicherheit

Alle öffentlichen static (Shared in Visual Basic) Member dieses Typs sind threadsicher. Die Threadsicherheit von Instanzmembern ist nicht gewährleistet.

Siehe auch

Referenz

DocumentIdProvider-Member

Microsoft.Office.DocumentManagement-Namespace