Question

Consider the following code:

string srcUrl = Request.Params["sourceUrl"]; 
SPList list = SPContext.Current.Web.GetList(srcUrl);

with MDS Feature disabled:

string srcUrl = "http://localhost/Freigegebene%20Dokumente/Forms/AllItems.aspx"

code is executed fine

with MDS Feature enabled:

string srcUrl = "http://localhost/_layouts/15/start.aspx#/Freigegebene%20Dokumente/Forms/AllItems.aspx"

FileNotFoundException occurs in the GetList() method

Is there another method of getting the list? Or a workaround when MDS is enabled?

Was it helpful?

Solution

It helped to use another parameter called: listId

string listId = Request.Params["listId"];
Guid listIdGuid = new Guid(listId);
list = SPContext.Current.Web.Lists[listIdGuid];

OTHER TIPS

Is there any reason to access list by SourceUrl property from a query string?

Use SPContext.Current.List to gets the list that is associated with the SharePoint context:

SPList currentList = SPContext.Current.List;

Update

Use SPWeb.GetListFromWebPartPageUrl method to get the list that is associated with the first Web Part on the specified Web Parts page, for example:

SPList  list = SPContext.Current.Web.GetListFromWebPartPageUrl(srcUrl);

where srcUrl points to a list view url from your example.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top