Search code examples
c#sharepointintegration

C# console and sharepoint link


this is the code use for get the data from the sharepoint site.

 string siteUrl = "https://sharesss.xyz.net/sites/xxx-xxx/training/Lists/";

 System.Net.NetworkCredential cred= new System.Net.NetworkCredential("username", "password", "Domainname");

 ClientContext context = new ClientContext(siteUrl);


      context.Credentials = cred;  
            Web web = context.Web;
            context.Load(web);
            context.ExecuteQuery();

And the execution show error:

There is no Web named \"/sites/XXXXXX/training/Lists/_vti_bin/sites.asmx\"."}

How to solve this issue?


Solution

  • string siteUrl = @"https://sharesss.xyz.net/sites/xxx-xxx/training";
                    System.Net.NetworkCredential cred = new System.Net.NetworkCredential("username", "password", "Domainname");
                    ClientContext clientContext = new ClientContext(siteUrl);
    
                    Web web = clientContext.Web;
    
                    clientContext.Credentials = cred;
    SharePointOnlineCredentials(  (username).ToString(), FetchPasswordFromConsole());
                    List oList = clientContext.Web.Lists.GetByTitle("Name Of List");
                    CamlQuery camlQuery = new CamlQuery();
                    camlQuery.ViewXml = "<View><Query><Where><Geq><FieldRef Name='ID'/>" +
                                        "<Value Type='Number'>10</Value></Geq></Where></Query><RowLimit>100</RowLimit></View>";
                    ListItemCollection collListItem = oList.GetItems(camlQuery);
                    clientContext.Load(web.Lists);
                    clientContext.Load(oList);
                    clientContext.Load(collListItem);
                    clientContext.ExecuteQuery();
    

    Changed the code like this and it works.