0

I am having the following exception when trying to get a list that I know it exists.

yes, I know the using should not be used in this case but thats not my code :), but I dont think thats the problem

 using (SPWeb CurrentSite = SPContext.Current.Site.RootWeb)
            {
                string listUrl = string.Format("{0}/Lists/RequestAccess", CurrentSite.Url);
                SPList list = CurrentSite.GetList(listUrl);

enter image description here

0

2 Answers 2

3

As per msdn SPWeb.GetList accepts server relative url, but you pass absolute url, may be this is the issue.

1
  • Use the CurrentSite.ServerRelativeUrl. Also ensure to check for the trailling backslash so you dont get two of them.
    – Roman
    Apr 14, 2012 at 2:43
1

If you are facing issues with SpWeb.Getlist() then instead of that you can SpWeb.Lists["ListName"] which takes list title as parameter. no need to provide the URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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