Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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

share|improve this answer
    
Use the CurrentSite.ServerRelativeUrl. Also ensure to check for the trailling backslash so you dont get two of them. –  Roman Apr 14 '12 at 2:43

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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