Document ID and Document Set updation
Document ID, a SharePoint service provides unique ID to individual document in library. You can activate this service by enabling site collection feature - Document ID settings.
Document Set is used for content organizer. This is being used to set/tagged a group of related documents in the library. Like, all documents related with LAW or HR or Product 24.5. This has been earlier SharePoint 2010 and it is a kind content type. This is site collection feature and you can find it as Document Sets. What is doces internally is created a folder (based on the document tag) and keep the related documents there.
If you use both the Document Set and Document ID, then every Document Set also having an unique ID (as these are related folders resides under library) same as individual document do have.
During migration, sometimes DocumentID not migrated properly by different major migration tools. Could be because Document Set not migrated properly and related documents (under that Document Set) got migrated but keep in orphan state in destination environment, which causes them to have new Document ID.
Following script is very basic version which helps to read Document Set in new location and update them with a new ID. This could be used in such cases where you found document ID is not matching in your source and destination. Manually you can run this tool to update your Document ID in destination matching with source.
Following are the CAML query example which could be used to retrieve item collection based on placing Document ID in search criteria. Internal name of Document ID is _dlc_DocId.
Happy Coding!
Document Set is used for content organizer. This is being used to set/tagged a group of related documents in the library. Like, all documents related with LAW or HR or Product 24.5. This has been earlier SharePoint 2010 and it is a kind content type. This is site collection feature and you can find it as Document Sets. What is doces internally is created a folder (based on the document tag) and keep the related documents there.
If you use both the Document Set and Document ID, then every Document Set also having an unique ID (as these are related folders resides under library) same as individual document do have.
During migration, sometimes DocumentID not migrated properly by different major migration tools. Could be because Document Set not migrated properly and related documents (under that Document Set) got migrated but keep in orphan state in destination environment, which causes them to have new Document ID.
Following script is very basic version which helps to read Document Set in new location and update them with a new ID. This could be used in such cases where you found document ID is not matching in your source and destination. Manually you can run this tool to update your Document ID in destination matching with source.
Following are the CAML query example which could be used to retrieve item collection based on placing Document ID in search criteria. Internal name of Document ID is _dlc_DocId.
cmlQuery.ViewXml
= "<View><Query><Where><Geq><FieldRef
Name='ID'/>" +
"<Value
Type='Number'>1574</Value></Geq></Where></Query><RowLimit>10</RowLimit></View>";
cmlQuery.ViewXml = "<View><Query><Where><Contains><FieldRef
Name='_dlc_DocId'/>" +
"<Value
Type='Computed'>4E557W7JJA26-2121061171-9310</Value></Contains></Where></Query><RowLimit>10</RowLimit></View>";
Here the source code, which is very basic and could be adjusted based on your location.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using System.Runtime.InteropServices;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using Microsoft.VisualBasic;
namespace PreMigration
{
class UpdateInfoPathLinks
{
static string
siteCollectionUrl = "https://demo.sharepoint.com/sites/TaxFedDocD";
static string
ServiceUserName = "himz-ps@demo.onmicrosoft.com";
static string
ServicePassword = "Geek234@";
static string
subSiteUrl = "Active/";
static string libTitle
= "Asset Management - 2013 - 2014";
ClientContext clientContext;
static void Main(string[] args)
{
FixLinks();
}
static ClientContext GetonlineContext()
{
var securePassword = new System.Security.SecureString();
foreach (char c in ServicePassword)
{
securePassword.AppendChar(c);
}
var onlineCredentials = new SharePointOnlineCredentials(ServiceUserName, securePassword);
var context = new ClientContext(siteCollectionUrl);
context.Credentials =
onlineCredentials;
return context;
}
public static void FixLinks()
{
using ( ClientContext clientContext = GetonlineContext())
{
clientContext.RequestTimeout =
3600000;
Web web = null;
if (subSiteUrl.Length.Equals(0))
web = clientContext.Web;
Site site = clientContext.Site;
web = site.OpenWeb(subSiteUrl);
clientContext.Load(web);
clientContext.ExecuteQuery();
List docLib =
web.Lists.GetByTitle(libTitle);
CamlQuery cmlQuery = new CamlQuery();
/*cmlQuery.ViewXml
= "<View><Query><Where><Geq><FieldRef
Name='ID'/>" +
"<Value
Type='Number'>1574</Value></Geq></Where></Query><RowLimit>10</RowLimit></View>";
*/
//4E557W7JJA26-2121061171-9310
cmlQuery.ViewXml = "<View><Query><Where><Contains><FieldRef
Name='_dlc_DocId'/>" +
"<Value
Type='Computed'>4E557W7JJA26-2121061171-9310</Value></Contains></Where></Query><RowLimit>10</RowLimit></View>";
ListItemCollection collListItem = docLib.GetItems(cmlQuery);
clientContext.Load(collListItem);
clientContext.ExecuteQuery();
foreach (ListItem oListItem in collListItem)
{
if(oListItem.Id == 1574)
Console.WriteLine("1574 ID: {0} \nDocID: {1}", oListItem.Id, oListItem["_dlc_DocId"]);
else
Console.WriteLine("ID: {0} \nDocID: {1}",
oListItem.Id, oListItem["_dlc_DocId"]);
//Updaing
oListItem["_dlc_DocId"] = "4E557W7JJA26-2121061555-9999";
oListItem.Update();
clientContext.ExecuteQuery();
}
Console.ReadLine();
}
}
public static string ReplaceHostName(Match m)
{
if (m.Value.EndsWith(".xsn", StringComparison.OrdinalIgnoreCase))
return m.Value;
else
return Regex.Replace(m.Value, oldUrl, newUrl, RegexOptions.IgnoreCase);
}
}
}
Comments
Post a Comment