Thursday, May 12, 2011

Get SharePoint webservice list to DataTable

       public DataTable GetCountryDataTable()
        {
            DataTable dtTable = null;
            try
            {
                SharePointList.Lists oList = new SharePointList.Lists();
                oList.PreAuthenticate = true;
                oList.Credentials = new System.Net.NetworkCredential(UserName, Password, Domain);
                oList.Url = Url;
                XmlNode itemCollection = oList.GetListItems("CountryList", string.Empty, null, null, "0", null, "");
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(itemCollection.OuterXml);
                DataSet ds = new DataSet();
                StringReader stringReader = new StringReader(xmlDoc.OuterXml);
                ds.ReadXml(stringReader);
                stringReader.Dispose();
                if (ds.Tables[1].Rows.Count > 0)
                {
                    dtTable = ds.Tables[1];
                }
            }
            catch (Exception ex)
            {
                Err.ErrorLog(HttpContext.Current.Server.MapPath("Logs/ErrorLog"), "GetCountryDataTable Method:" + ex.Message);
            }
            finally
            {
            }
            return dtTable;
        }

No comments:

101% shares

101% shares
about me