Skip to content

@kobi /gist:601848
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
//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
Something went wrong with that request. Please try again.