Esempio n. 1
0
        private List <NewsData> FillDataList(SPListItemCollection collListItems)
        {
            List <NewsData> _rows = new List <NewsData>();

            foreach (SPListItem oListItem in collListItems)
            {
                NewsData _row = new NewsData();
                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);
        }
Esempio n. 2
0
        private List <NewsData> 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 <NewsData> _rows = new List <NewsData>();

            foreach (XmlNode datanode in nodelist)
            {
                NewsData _row = new NewsData();
                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);
        }
Esempio n. 3
0
        public List <NewsData> 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 <NewsData>  dt = new List <NewsData>();

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

                NewsData r = new NewsData();
                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);
        }