Document Library fluent API 4.4 issue
Hi Everyone,
I have this method working fine in version 4.1 SP3,
but will throw the exception below when in version 4.4
public static string GetDocumentUrl(string library, string docName) string r = string.Empty; var lib = App.WorkWith().DocumentLibraries().Where(l => l.Title == library).Get().FirstOrDefault(); if (lib != null) var doc = lib.Documents.Where(d => d.Title == docName).FirstOrDefault(); if (doc != null) r = doc.MediaUrl; return r;
Hello Ernesto,
I have taken your code and modified it a bit, since it was returning an object reference error. Please check the following code sample as well as the changes I have made to your code:
protected void Page_Load(object sender, EventArgs e)
GetDocumentUrl("text", "Default Library");
public static string GetDocumentUrl(string docName, string libName)
string r = string.Empty;
LibrariesManager docManager = LibrariesManager.GetManager();
DocumentLibrary library = docManager.GetDocumentLibraries().Where(l => l.Title == libName).FirstOrDefault();
if (library != null)
var doc = docManager.GetDocuments().Where(d => d.Title == docName).FirstOrDefault();
if (doc != null)
//Will return the resolved absolute URL
var docUrl = doc.Url;
//Will return the default relative URL (i.e. /documentsroot/library/document
var docUrl1 = doc.Urls.Where(u => u.RedirectToDefault == false).SingleOrDefault().Url;
//Will return the properly resolved document mediaUrl. You can use doc.ResolveMediaUrl() and pass a boolean parameter to it
//that will tell it to rerutn absolute or relative Url. By default it returns resolved absolute URL
var docUrl2 = doc.MediaUrl;
r = docUrl2;
return r;
Thanks Victor, using the LibrariesManager did the trick.