tags:

views:

34

answers:

1

Looks like other people have had this issue, but I would like to understand how to target a column if there are spaces in a list column name when using the code below. Here is what I have:

    SPWeb oWebsite = SPContext.Current.Web;
    SPList oList = oWebsite.Lists["Project Info"];
    SPListItemCollection collItem = oList.GetItems("Project Description");

    if (collItem.Count > 0)
    {
        foreach (SPListItem oItem in collItem)
        {
            description = oItem["Project Description"].ToString();
        }
    }

If I create the list field "Project Description" with underscores for the column name (Project_Description), then it works just fine, but with the code above I get an error: Value does not fall within the expected range

Looks like there is something with the display vs internal name of the column. Can someone help me with this? Thanks.

+1  A: 

Try "Project_x0020_Description". AFAIK this works when using the web services. Not sure whether it also helps in your case.

Here is some more information: http://www.davehunter.co.uk/Blog/Lists/Posts/Post.aspx?ID=95

michid
Thanks for that.
Josh