SharePoint Blogs / SharePoint University
SharePoint Blogs and SharePoint University - all in one place!
Need SharePoint Training? Attend a SharePoint Bootcamp!

Please delete cookies related to sharepointblogs.com and sharepointu.com to resolve login issues!

SPWeb fails to return the list
All About SharePoint - S.S. Ahmed - MVP Microsoft SharePoint

When working on large applications, we usually make mistakes and then spend time debugging the errors that occur because of the mistakes that we make during programming but there are some errors that occur even if you don't make any mistake. Have a look at the following code:

SPWeb web = Site.OpenWeb(SPContext.Current.Web.ID);
string strList = SPContext.Current.Web.Url.Substring( .... substring processing ....);
SPList list = web.Lists[strList]; //This line gives error!

Do you see any problem with this code? I didn't notice any thing. It gave me the following error:

Value does not fall within the expected range.<BR/>Source: Microsoft.SharePoint<BR/>Stack trace: at Microsoft.SharePoint.SPListCollection.GetListByName(String strListName, Boolean bThrowException)

at Microsoft.SharePoint.SPListCollection.get_Item(String strListName)

The reason of the error turned out to be the list name. The list name had parentheses which resulted in the error. In small companies, you are the all in all when working on a project but in big companies or when working on large projects, there are several people involved in the project. The list was created by the SharePoint admin and I was getting the list name programmatically. I didn't know the list name had parentheses in it. When you load such a list in browser, SharePoint automatically removes parentheses from the list name and the list works fine but when you try to access the same list programmatically, SharePoint gives you an error. As you will notice, in the code above, I am extracting the list name from "SPContext.Current.Web.Url" and it returns the list name without parentheses in it while the actual list name has parentheses and hence you get an error. Even if you add parentheses to the list name (in your code), you still get an error but a different one. It's a SPException error and returns following message:

Action can not be completed.

Conclusion: Do not use parentheses in list name.


Posted 10-16-2007 12:05 PM by ssa

Comments

Blogger Loser » SPWeb fails to return the list wrote Blogger Loser &raquo; SPWeb fails to return the list
on 10-16-2007 11:23 AM

Pingback from  Blogger Loser &raquo; SPWeb fails to return the list

Blogger Loser » SPWeb fails to return the list wrote Blogger Loser &raquo; SPWeb fails to return the list
on 10-17-2007 12:48 PM

Pingback from  Blogger Loser &raquo; SPWeb fails to return the list

Jas wrote re: SPWeb fails to return the list
on 05-26-2008 7:49 AM

There is another issue i wasted several hours on !

Check to see if the List is in the Web application that is being accessed in the first place! The List we imported was in the default app but we were trying to access it from a new site created within.....

Zobayer Rabbi wrote re: SPWeb fails to return the list
on 11-16-2008 12:27 AM

I deploy FBA from codeplex. when i login as Site Administrator it works nicely. But when i try to access as a

normal user i got the following error:

Value does not fall within the expected range.   at Microsoft.SharePoint.SPListCollection.GetListByName(String strListName, Boolean bThrowException)

  at Microsoft.SharePoint.SPListCollection.get_Item(String strListName)

  at CKS.FormsBasedAuthentication.FBAUsersView.ExecuteSelect(DataSourceSelectArguments selectArgs)

  at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)

  at System.Web.UI.WebControls.DataBoundControl.PerformSelect()

  at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()

  at System.Web.UI.WebControls.GridView.DataBind()

  at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()

  at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()

  at System.Web.UI.Control.EnsureChildControls()

  at System.Web.UI.Control.PreRenderRecursiveInternal()

  at System.Web.UI.Control.PreRenderRecursiveInternal()

  at System.Web.UI.Control.PreRenderRecursiveInternal()

  at System.Web.UI.Control.PreRenderRecursiveInternal()

  at System.Web.UI.Control.PreRenderRecursiveInternal()

  at System.Web.UI.Control.PreRenderRecursiveInternal()

  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

As per your article i found the lines as following:

SPWeb thisweb = site.RootWeb;

// we only display users that have been added to SharePoint

// we use the localized name, safe for non-English SharePoint servers

SPList list = thisweb.Lists [SPUtility.GetLocalizedString("$Resources:userinfo_schema_listtitle", "core", thisweb.Language)];

What change do i need t odo here?

ssa wrote re: SPWeb fails to return the list
on 01-17-2009 9:41 AM

Zobayer:

List title can be different from the actual list name. The error you mentioned clearly shows that list name is not correct. Error suggests that list is not found because of the incorrect name. Check the list name.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Need SharePoint Training? Attend a SharePoint Bootcamp!
Posts (c) their respective authors. Everything else (c) 2009 SharePoint Experts, Inc.