Created
September 28, 2010 21:43
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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