Skip to content

Instantly share code, notes, and snippets.

@kobi
Created September 28, 2010 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobi/601848 to your computer and use it in GitHub Desktop.
Save kobi/601848 to your computer and use it in GitHub Desktop.
//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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment