private List <SupplierData> FillDataList(SPListItemCollection collListItems) { List <SupplierData> _rows = new List <SupplierData>(); foreach (SPListItem oListItem in collListItems) { SupplierData _row = new SupplierData(); foreach (PropertyInfo pi in _row.GetProperties()) { string _field = pi.Name; if (pi.CanWrite) { try { if (oListItem[_field] != null) { pi.SetValue(_row, oListItem[_field], null); } else { pi.SetValue(_row, null, null); } } catch { pi.SetValue(_row, null, null); } } } _rows.Add(_row); } return(_rows); }
private List <SupplierData> GetDataList(XmlNode items) { XmlDocument docItems = new XmlDocument(); docItems.LoadXml("<?xml version='1.0' ?>" + items.OuterXml); XmlNamespaceManager nsMgr = new XmlNamespaceManager(docItems.NameTable); nsMgr.AddNamespace("s", "uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"); nsMgr.AddNamespace("dt", "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"); nsMgr.AddNamespace("rs", "urn:schemas-microsoft-com:rowset"); nsMgr.AddNamespace("z", "#RowsetSchema"); nsMgr.AddNamespace("mha", "http://schemas.microsoft.com/sharepoint/soap/"); XmlNodeList nodelist = docItems.SelectNodes("//mha:listitems/rs:data/z:row", nsMgr); List <SupplierData> _rows = new List <SupplierData>(); foreach (XmlNode datanode in nodelist) { SupplierData _row = new SupplierData(); foreach (PropertyInfo pi in _row.GetProperties()) { string _field = "ows_" + pi.Name; string _type = pi.PropertyType.Name; if (pi.CanWrite) { try { if (datanode.Attributes[_field] != null) { switch (_type) { case "Int32": pi.SetValue(_row, int.Parse((string)datanode.Attributes[_field].Value), null); break; case "String": pi.SetValue(_row, (string)datanode.Attributes[_field].Value, null); break; default: pi.SetValue(_row, datanode.Attributes[_field].Value, null); break; } } else { pi.SetValue(_row, null, null); } } catch { pi.SetValue(_row, null, null); } } } _rows.Add(_row); } return(_rows); }
public List <SupplierData> GetListsOld() { SPDataSource ds = new SPDataSource(); ds.DataSourceMode = SPDataSourceMode.List; ds.UseInternalName = true; ds.Scope = SPViewScope.Recursive; ds.IncludeHidden = true; string queryString; //queryString = "<View><ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/><FieldRef Name='PermMask'/></ViewFields><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>5</Value></Eq></Where></Query></View>"; //queryString = "<View><ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/><FieldRef Name='PermMask'/></View>"; queryString = "<View></View>"; ds.SelectCommand = queryString; Parameter dbParam_ListId = new Parameter("ListID"); dbParam_ListId.DefaultValue = "DF806E7E-0073-4202-99E3-C4A269E2FA5D"; ds.SelectParameters.Add(dbParam_ListId); SPDataSourceView dsw; List <SupplierData> dt = new List <SupplierData>(); dsw = ds.GetView(); SPList xlist = dsw.List; SPViewCollection colViews = xlist.Views; foreach (SPView vView in colViews) { } /* * SPListItem newFolder = xlist.Items.Add(xlist.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, null); * if (newFolder != null) * { * newFolder["Title"] = "Min Nye Folder"; * newFolder.Update(); * } */ System.Web.UI.DataSourceSelectArguments args = new System.Web.UI.DataSourceSelectArguments(); SPDataSourceViewResultItem[] arrResult = (SPDataSourceViewResultItem[])dsw.Select(args); foreach (SPDataSourceViewResultItem Result in arrResult) { SPListItem oListItem = (SPListItem)Result.ResultItem; //SPField myField = xitem.Fields[new Guid("{FE7E79DD-DD68-438e-A960-E3686025D44B}")]; SupplierData r = new SupplierData(); foreach (SPField ofield in oListItem.Fields) { string tekst; try { tekst = ">" + ofield.Title + "< >" + ofield.InternalName + "<>" + oListItem[ofield.Id] + "<"; } catch { //OK } switch (ofield.InternalName) { case "ID": r.ID = (int)oListItem[ofield.Id]; break; case "Title": r.Title = (string)oListItem[ofield.Id]; break; } } dt.Add(r); } return(dt); }