2

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?

2
  • You can try string relativeurl = SPContext.Current.Web.GetServerRelativeUrlFromUrl(srcUrl); and then use relative url to get the list.
    – Aanchal
    Sep 8, 2014 at 9:53
  • Not pretty but what about: if( srcUrl.Contains("/_layouts/15/start.aspx#") { srcUrl = srcUrl.Replace("/_layouts/15/start.aspx#", ""); } Sep 8, 2014 at 12:23

2 Answers 2

1

It helped to use another parameter called: listId

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

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.

2
  • In this particular scenario SPContext.Current.List is null Sep 8, 2014 at 11:49
  • I see, please check the updated answer Sep 8, 2014 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.