-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPList.cs
113 lines (101 loc) · 4.61 KB
/
SPList.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
/*
* My idea behind this class is it is basically a container for a collection of columns, and a collection of rows
* It knows how to create itself if you give it a valid xml output from the GetList web service call, and the GetListItems web service call
*
* Matt Kalal
*/
namespace SP2010WS
{
public class SPList
{
private List<ColumnDef> ColumnDefs;
private List<List<string>> Rows;
public SPList()
{
ColumnDefs = new List<ColumnDef>();
Rows = new List<List<string>>();
}
public void SetError()
{
ColumnDefs.Add(new ColumnDef("col1", "col1", "TEXT", 80));
Rows.Add(new List<string>() { "Error, there is a problem getting the data set" });
}
public int LoadList(System.Xml.XmlNode ListXML, System.Xml.XmlNode ListItemsXML)
{
ColumnDefs = new List<ColumnDef>();
Rows = new List<List<string>>();
List<string> tempLst = new List<string>();
string ListID = GetAttribute(ListXML, "ID");
foreach (System.Xml.XmlNode xnode in ListXML)
{
// I really only care about the "Fields" node, but the "selectSingleNode" with an xPath of "/List/Fields" isn't working
// probably because of a namespace; perhaps later I'll figure it out but a quick loop looking at the name seems to be OK as a workaround
if (xnode.Name.ToString().Equals("Fields"))
{
foreach (System.Xml.XmlNode FX in xnode)
{
//
// It's a little long, but the logic that works is the field is not hidden, and [the static name is "title", or the sourceid is the same as the ListID]
//
if (!(GetAttribute(FX, "Hidden").Equals("TRUE", StringComparison.CurrentCultureIgnoreCase)) && (GetAttribute(FX, "StaticName").Equals("title", StringComparison.CurrentCultureIgnoreCase) || GetAttribute(FX, "SourceID").Equals(ListID, StringComparison.CurrentCultureIgnoreCase)))
{
ColumnDefs.Add(new ColumnDef(GetAttribute(FX, "DisplayName"), GetAttribute(FX, "StaticName"), GetAttribute(FX, "Type"), GetAttribute(FX, "MaxLength")));
}
}
}
}
foreach (System.Xml.XmlNode linode in ListItemsXML)
//
// We just want the rs:data nodes, and there is probably a better way to do this, but it works
//
{
if (linode.Name.ToString().Equals("rs:data", StringComparison.CurrentCultureIgnoreCase))
{
foreach (System.Xml.XmlNode rownode in linode)
{
if (rownode.Name.ToString().Equals("z:row", StringComparison.CurrentCultureIgnoreCase))
{
foreach (ColumnDef cd in ColumnDefs)
{
//
// The point with this "ows_" is the columns out of SharePoint web service call
// all started with "ows_" and there is probably a reason for that but I didn't want
// to go through the spec. This works just fine.
//
tempLst.Add(GetAttribute(rownode, "ows_" + cd.GetInternalColumnName()));
}
Rows.Add(new List<string>(tempLst));
tempLst.Clear();
}
}
}
}
return 1;
}
public List<List<string>> GetRows()
{
return Rows;
}
public List<ColumnDef> GetColumnDefs()
{
return ColumnDefs;
}
//
// I made this function because not all of the attributes are present, and when they aren't
// it was easier just to return a string "NULL" than it was to try and program around it
//
private string GetAttribute(System.Xml.XmlNode XmlNode, string AttName)
{
try
{
return XmlNode.Attributes[AttName].Value;
}
catch (NullReferenceException)
{
return "NULL";
}
}
}
}