Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.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# c遍历对象成员_C#_Sharepoint - Fatal编程技术网

C# c遍历对象成员

C# c遍历对象成员,c#,sharepoint,C#,Sharepoint,此处的上下文是我希望查看sharepoint列表中的对象所具有的权限。 但问题与C有关 Sharepoint有一个名为SPListItem的对象,您可以通过迭代该对象的索引来查看该对象的各种详细信息 我可以使用整数splistem[I]遍历splistem的索引。但是,问题是我不知道我的程序打印出的是什么属性/细节 如何打印出索引的名称和索引值 这是我的密码 using System; using System.Collections.Generic; using System.Linq; us

此处的上下文是我希望查看sharepoint列表中的对象所具有的权限。 但问题与C有关

Sharepoint有一个名为SPListItem的对象,您可以通过迭代该对象的索引来查看该对象的各种详细信息

我可以使用整数splistem[I]遍历splistem的索引。但是,问题是我不知道我的程序打印出的是什么属性/细节

如何打印出索引的名称和索引值

这是我的密码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System;
using Microsoft.SharePoint;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("-----");
            using (SPSite site = new SPSite("http://c4968397007/sites/anupamsworkspace/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList oSPList = web.Lists["Check2"];
                    SPListItem oSPListItem = oSPList.Items[0];

                    for (int i = 0; i < 100;i++ )
                        //printing out the index value using int index, how do I print the name of the value it's printing out ? 
                        Console.WriteLine(oSPListItem[i]);
                }
            }
            Console.ReadLine();
        }
    }
}

你可以使用下面的方法

 using (SPWeb web = site.OpenWeb())
            {
               SPList list = web.GetList("Check2");
               if (list.ItemCount > 0)
               {
                  SPListItem item = list.Items[0];
                  Hashtable ht = item.Properties;
                  foreach (DictionaryEntry de in ht)
                     Console.WriteLine("Key: {0}  Value: {1}", de.Key, de.Value);
               }
            }
}

这应该可以做到:

using (SPSite site = new SPSite("http://c4968397007/sites/anupamsworkspace/"))
{
    using (SPWeb web = site.OpenWeb())
    {
        var list = web.Lists["Check2"];
        var item = list.Items[0];
        foreach (var field in list.Fields)
        {
            Console.WriteLine("Key: {0} Value: {1}", field.StaticName, item[field.StaticName])
        }
    }
}
问候,,
Martin

我不仅仅需要项目。属性我需要打印所有索引。。。其中大约有75个。感谢您的回复,martin,但visualstudio抱怨该对象未包含StaticName的定义。有什么解决方法吗?这很奇怪,field应该是一个带有StaticName属性的SPField对象。将foreach语句更改为:list.Fields中的foreach SPField字段