Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从SharePoint字段选择列检索所有项目_C#_Sharepoint - Fatal编程技术网

C# 从SharePoint字段选择列检索所有项目

C# 从SharePoint字段选择列检索所有项目,c#,sharepoint,C#,Sharepoint,我正在使用SharePoint服务器,并试图通过编程方式将服务请求添加到microsoft的呼叫中心应用程序模板中。到目前为止,我已经取得了相当大的成功。我可以为特定客户添加呼叫,并指定特定的支持技术: private enum FieldNames { [EnumExtension.Value("Service Request")] ServiceRequest, [EnumExtension.Value("Customer")] Customer, [

我正在使用SharePoint服务器,并试图通过编程方式将服务请求添加到microsoft的呼叫中心应用程序模板中。到目前为止,我已经取得了相当大的成功。我可以为特定客户添加呼叫,并指定特定的支持技术:

private enum FieldNames
{
    [EnumExtension.Value("Service Request")]
    ServiceRequest,
    [EnumExtension.Value("Customer")]
    Customer,
    [EnumExtension.Value("Service Representative")]
    ServiceRepresentative,
    [EnumExtension.Value("Assigned To")]
    AssignedTo,
    [EnumExtension.Value("Software")]
    Software,
    [EnumExtension.Value("Category")]
    Category
}
private void CreateServiceCall(string serviceCallTitle, string customerName, string serviceRep)
{
    SPSite allSites = new SPSite(siteURL);
    SPWeb site = allSites.AllWebs[siteName];
    SPListItemCollection requestsList = site.Lists[serviceRequests].Items;
    SPListItem item = requestsList.Add();

    SPFieldLookup customerLookup = item.Fields[FieldNames.Customer.Value()] as SPFieldLookup;

    item[FieldNames.ServiceRequest.Value()] = serviceCallTitle;

    if (customerLookup != null)
    {
        using (SPWeb lookupWeb = allSites.OpenWeb(customerLookup.LookupWebId))
        {
            SPList lookupList = lookupWeb.Lists.GetList(new Guid(customerLookup.LookupList), false);
            foreach (SPListItem listItem in lookupList.Items)
            {
                if (listItem[customerLookup.LookupField].ToString() != customerName) continue;

                item[FieldNames.Customer.Value()] = new SPFieldLookupValue(listItem.ID, customerName);
                break;
            }
        }
    }
    SPUserCollection userCollection = site.SiteUsers;
    if (userCollection != null)
    {
        foreach (SPUser user in userCollection)
        {
            if (user.Name != serviceRep) continue;

            item[FieldNames.AssignedTo.Value()] = user;
            break;
        }
    }

    item.Update();

    site.Close();
    allSites.Close();
}
我在默认列表中添加了两个自定义列(类别、软件):

我在SharePoint中填充了这两列,现在我想检索这些数据,以便在我发布的代码片段中使用这些数据,为调用分配适当的类别/软件等。我无法在代码中获取列表,我尝试使用
项[“软件”]
站点。列表[“软件”]
和其他一些,但到目前为止,我只找到了
null


有人能为我指出正确的方向吗?谢谢

SPFieldMultiChoice
和相关字段具有
选项
属性:

SPFieldMultiChoice software = item.Fields[FieldNames.Software.Value()] as SPFieldMultiChoice;
StringCollection softwareChoices = software.Choices;
如果需要在字段上设置值,请使用
SPFieldMultiChoiceValue
类型:

SPFieldMultiChoiceValue values = new SPFieldMultiChoiceValue();
values.Add("Choice 1");
values.Add("Choice 2");
item[FieldNames.Software.Value()] = values;

此示例演示如何从
SPList
中检索
SPFieldMultiChoice
对象——请注意,您也可以从
SPList
中获取此对象,这对我来说更有用,因为我想在获取列表引用之后,但在开始迭代列表项之前访问Choices属性。只需访问
SPList.Fields
属性,访问方式与示例中访问
item.Fields
的方式完全相同。