public
Last active

  • Download Gist
gistfile1.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
//Sharepoint's DocumentId.FindUrlById , used for
// http://kobikobi.wordpress.com/2010/09/29/sharepoint-2010-using-document-id-to-link-to-a-specific-version/
 
public static string FindUrlById(SPSite site, string docId, string versionLabel)
{
if (site == null)
{
throw new ArgumentNullException("site");
}
string[] documentUrlsById = DocIdLookup.DoSearch(site, docId);
if ((documentUrlsById == null) || (documentUrlsById.Length == 0))
{
documentUrlsById = GetProvider(site).GetDocumentUrlsById(site, docId);
}
if ((documentUrlsById != null) && (documentUrlsById.Length == 1))
{
string requestUrl = documentUrlsById[0];
using (SPSite site2 = new SPSite(requestUrl))
{
using (SPWeb web = site2.OpenWeb())
{
SPFile file = web.GetFile(requestUrl);
if (file != null)
{
SPListItem item = file.Item;
if (item != null)
{
SPListItemVersion versionFromLabel = item.Versions.GetVersionFromLabel(versionLabel);
if (versionFromLabel != null)
{
return (item.Web.Url + '/' + versionFromLabel.Url);
}
}
}
}
}
}
return null;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.