List 객체를 사용하여 사용자 속성을 저장하고 있습니다.인덱스가 범위를 벗어났습니다. 음수가 아니어야하며 List에있는 콜렉션의 크기보다 작아야합니다. <string>
내 코드입니다 : 나는이 프로그램을 실행할 때 내가 위에서 언급 한 오류가 발생하고
string department=string.Empty;
List<string> otherDepartments = new List<string>();
int no;
string result = string.Empty;
string queryText = string.Empty;
using (SPSite siteCollection = SPContext.Current.Site)
{
using(SPWeb site = siteCollection.OpenWeb())
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPUser spUser = site.CurrentUser;
SPServiceContext context = SPServiceContext.GetContext(siteCollection);
UserProfileManager upm = new UserProfileManager(context);
UserProfile profile = upm.GetUserProfile(spUser.LoginName);
department = profile["oiplbDepartment"].Value.ToString();
UserProfileValueCollection otherDept = profile["oiplbOtherDepartments"];
if (otherDept.Count != 0)
{
foreach (var prop in otherDept)
{
otherDepartments.Add(prop.ToString());
}
}
Label1.Text = department + " Ohter Departments " + otherDepartments;
});
SPList list = site.Lists["Events"];
SPListItemCollection itemColl;
SPQuery query = new SPQuery();
no = 1 + otherDepartments.Count;
for (int i = 1; i <= no; i++)
{
if (no == 1)
{
result = "<or> <Eq><FieldRef Name='oiplbDepartment' /><Value Type='TaxonomyFieldType'>"+department+"</Value></Eq>"+"</or>";
break;
}
else if (i == 2)
{
result = "<or> <Eq><FieldRef Name='oiplbDepartment' /><Value Type='TaxonomyFieldType'>" + department + "</Value></Eq>" +
"<Eq><FieldRef Name='oiplbDepartment' /><Value Type='TaxonomyFieldType'>" + otherDepartments[i-1] + "</Value></Eq>";
}
else if(i >= 3)
{
result = generateOr(result,otherDepartments[i-1]);
}
}
queryText = "<where>"+result +"</Where>";
query.Query = queryText;
itemColl = list.GetItems(query);
Grid.DataSource = itemColl.GetDataTable();
Grid.DataBind();
}
}
public static string generateOr(string temp, string value)
{
string r = "<or>" + temp + " <Eq><FieldRef Name='oiplbDepartment' /><Value Type='TaxonomyFieldType'>" + value + "</Value></Eq> </or>";
return r;
}
.
그렇지 않으면 속성을 사용할 수있는 경우에만 값을 삽입합니다.
하지만 오류가 발생하는 이유는 무엇입니까?
어떤 라인에서 좋습니까? – Arran
이 줄을 변경해보십시오 : for (int i = 1; i <= no; i ++)'for (int i = 1; i
아니요, for (int i = 1, k = 0; i <= 아니오; i ++, k ++ 0')와 같은 for 루프를 변경하고'k '를 통해리스트 인덱스에 액세스 할 수 있습니까? –