Wednesday, 23 July 2014

Retrieving a WebSite List using SharePoint Web service

//Get Web Site Lists  
private static void GetLists(string url, string login, string password)
{
    //List WebService 
    Lists ls = new Lists();
    ls.PreAuthenticate = true;
    ls.Credentials = new NetworkCredential(login, password);
    ls.Url = url + @"/_vti_bin/lists.asmx";

    foreach (XmlNode list in ls.GetListCollection().ChildNodes)
    {
        //Check whether list is document library
        if (Convert.ToInt32(list.Attributes["ServerTemplate"].Value) != 0x65)
        {
            continue;
        }

        string title = list.Attributes["Title"].Value;
        string listUrl = list.Attributes["DefaultViewUrl"].Value.Replace(
                                         "/Forms/AllItems.aspx", string.Empty);

        char[] separator = new char[] { '/' };
        string listPath = url.Substring(0, url.LastIndexOf('/'));

        Console.WriteLine(listPath + listUrl + "/" + title);
        AddListsItems(url, title, login, password);
    }
}

0 comments:

Post a Comment