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 the following code

string[] listArray = new string[] {"some list", "Some other list"}
foreach (string s in listArray)
{
SPList listName = rootWeb.Lists[s];
}

Ok that should be enough to see whats going on, basically if i remove iCount from listArray[iCount] and replace it with a value then it works

If not I get the usual Unhandled exception was thrown by the sandboxed code wrappers Execute method which is the error you get when it doesn't work in the Sandbox.

Any help is appreciated Thanks Matt

share|improve this question
add comment

3 Answers

Aha... it may be relating to one of these:

  1. Your list doesn't exist
  2. You don't have permission to access it
  3. rootWeb is null

Try/Catch with validation?

share|improve this answer
    
I am passing in the same value as if I do it explicitly, I have debugged it and the value does get passed in correctly but it still does not work in the sandbox. –  Mattmoo May 17 '12 at 14:54
add comment

I guess i'm having a hard time even understanding why you need the icount. I would think the code should look like this:

string[] listArray = new string[] {"some list", "Some other list"} 
foreach (string s in listArray) 
{ 
string listName = s;

} 
share|improve this answer
    
OK yeah you're right on that front so I removed that and it still brings up the same error. So I will post the new code –  Mattmoo May 17 '12 at 14:22
add comment

Not sure why you are using iCount at all?

Does this work:

foreach (string s in listArray)
{
    string listName = s;
}

Alternatively

string[] listArray = new string[] { "some list", "Some other list" };

int len = listArray.Count<string>();

for (int i = 0; i < len; i++)
{
     string listName = listArray[i];
}

Otherwise dump in a try/catch which may be manifesting itself as a Sandbox error. Arrays can often have null/empty values too so worth validating the contents of the item in the array.

share|improve this answer
    
Beat me to it. :) –  Steve Lineberry May 17 '12 at 14:14
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.