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 have a list item with one field Classes which is a multiple choice lookup. I want to implement an ASPX page which contains a ListBox which is filled with values from the Classes field. The following method does that:

private void GetSelectedClasses()
{
    SPFieldLookupValueCollection currentSelection;

    using (SPWeb web = this.Web)
    {
        ClassesListBox.Items.Clear();

        currentSelection = item["Classes"] as SPFieldLookupValueCollection;
        foreach (SPFieldLookupValue value in currentSelection)
        {
            ClassesListBox.Items.Add(value.LookupValue);
        }
    }
}

This method works fine if I run/debug/deploy it with my account which is a SharePoint admin. However, when I run it under User1 account, which has contribute permissions on the site and the list which contains the list item, I get the strange error:

System.ArgumentException: Value does not fall within the expected range.

The error is happening in the line
currentSelection = item["Classes"] as SPFieldLookupValueCollection;
When I promote the User1 to Full Control permissions user or even site collection administrator, I am still getting the error. The ArgumentException appears to be firing because the field named Classes doesn't exist, allegedly. This is of course not true, because checking the item fields does list it and it all works well with my default account.

Could anyone help me out? I feel quite desperate. Thanks!

share|improve this question
    
I've also noticed that the same exception is thrown for all fields that are not of type text. This is really really weird. –  Boris Jun 11 '12 at 23:27
add comment

1 Answer 1

up vote 1 down vote accepted

Ok, I've solved it. I am not sure why, but when I use User1 account, I need to explicitly specify the fields I want to get when I am retrieving SPItem object. So, previously I have had instantiated the item object with the following line:

this.item = this.list.Items.GetItemById(Convert.ToInt32(itemId, CultureInfo.InvariantCulture));

But, in order to have my Classes field included in the query, I need to use:

this.item = this.list.GetItemByIdSelectedFields(Convert.ToInt32(itemId, CultureInfo.InvariantCulture), "Classes");

My GetSelectedClasses() method mentioned in the question body is actually correct.

share|improve this answer
add comment

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.