17 Sep 2011

Document Management


Document Sets

Document set is a special Content Type that holds multiple documents in a unique container

Purpose of document set is to store multiple documents belonging to the same project.

It has a custom user interface based on a dedicated welcome page, dedicated versioning of the entire set, specific workflows, synchronization of metadata between the document set and the items that it contains, and custom behaviors in general.


The basic ID of the Document Set content type is 0x0120D520, because it is inherited from the Document Collection Folder content type (ID 0x0120D5).
Folder content type (ID 0x0120)


Handling Document Sets by Code

namespace Microsoft.Office.DocumentManagement.DocumentSets

Main Members of the DocumentSet Class

Creates a DocumentSet instance object within an existing SPFolder instance.

Exports the current DocumentSet into a packaged (ZIP compressed) file.

Static method that gets the DocumentSet object from a specified SPFolder object.

Import Static method that imports a DocumentSet from a package previously exported
via the Export method.

Exporting a document set into a .ZIP file

   1:  using (SPSite site = new SPSite("http://dev.sp2010.local/")) {
   2:  using (SPWeb web = site.OpenWeb()) {
   3:  SPList library = web.Lists["Work Orders"];
   4:  // Search for items of type Document Set
   5:  foreach (SPListItem item in library.Items) {
   6:  // In case the ContentTypeId of the item inherits from a DocumentSet
   7:  if (DocumentSetTemplate.Id.IsParentOf(item.ContentTypeId)) {
   8:  // Get a reference to the DocumentSet instance
   9:  DocumentSet ds = DocumentSet.GetDocumentSet(item.Folder);
  10:  // Export the item as a .ZIP content
  11:  Byte[] package = ds.Export();
  12:  using (FileStream fs = new FileStream(ds.Item.Title + ".zip",
  13:  FileMode.CreateNew, FileAccess.Write, FileShare.None)) {
  14:  using(BinaryWriter bw = new BinaryWriter(fs)) {
  15:  bw.Write(package);
  16:  bw.Flush();
  17:  }
  18:  }
  19:  }
  20:  }
  21:  }
  22:  }


Document ID – * New feature SharePoint2010

This is a provider-based identifier generator that creates unique identifiers for documents in libraries so that they can be used to retrieve documents independently from their location.

Activate -  Site Collection-level feature, called “Document ID Service,”




Document path based on document ID ( Document Id feature must enabled)
http://{your site URL}/_layouts/DocIdRedir.aspx?ID={Document ID Value}

Custom Document ID Provider


   1:  namespace Microsoft.Office.DocumentManagement {
   2:  public abstract class DocumentIdProvider {
   3:  protected DocumentIdProvider();
   4:  public abstract bool DoCustomSearchBeforeDefaultSearch { get; }
   5:  public abstract string GenerateDocumentId(SPListItem listItem);
   6:  public abstract string[] GetDocumentUrlsById(SPSite site,
   7:  string documentId);
   8:  public abstract string GetSampleDocumentIdText(SPSite site);
   9:  }
  10:  }


After implementing a custom Document ID Provider, you need to register it to make it the
default provider.

No comments:

Post a Comment