2014-09-25 5 views
0

Контекст здесь в том, что я хочу видеть права доступа к объекту в списке sharepoint. Но вопрос имеет отношение к C#C# итерация через членов объекта

Sharepoint имеет объект под названием SPListItem, и вы можете просматривать различные детали об объекте, итерируя его индекс.

Я могу выполнить итерацию по индексу SPListItem с использованием целых чисел (splistitem[i]). Но проблема в том, что я не знаю, какое свойство/деталь - это моя программа.

Как распечатать имя индекса и значение индекса?

вот мой код

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(); 
     } 
    } 
} 

ответ

0

Это должно сделать трюк:

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]) 
     } 
    } 
} 

С уважением, Мартин

+0

спасибо за ваш ответ martin, но visualstudio жалуется, что «Object не содержит определения для StaticName». Любая работа для этого? –

+0

Thats странно, поле должно быть объектом SPField со свойством StaticName (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfield.staticname(v=office.15).aspx). Измените оператор foreach на: foreach (поле SPField в списке.Fields) –

0

Вы можете использовать ниже подход

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); 
       } 
      } 
} 
+0

я надеваю» t просто нужно 'item.pro perties' Мне нужно распечатать все индексы ... есть около 75 из них –

Смежные вопросы