0

I just started learning CSOM, I want to get all lists from specific site provided by user, and display them in WinForms app. Here is the code of acquiring lists:

    class ListCheckRepo : IListCheckRepo
{
    public ListCollection GetLists(string url)
    {
        ClientContext clientcontext = new ClientContext(url);
        Web web = clientcontext.Web;
        ListCollection listColl = web.Lists;
        clientcontext.Load(listColl);

        clientcontext.ExecuteQuery();
        return listColl;
    }
}

The problem is an error "Invalid file name" at ExecuteQuery

The file name you specified could not be used.  
It may be the name of an existing file or directory, 
or you may not have permission to access the file.

I Have literally no idea what it means, which file or directory is it talking about. The URL Im providing is a working one, also I was working with msdn documentation while writing it.

0

You can use the below sample code to get the list collection in a site and display them in a console. Change the display code accordingly to use with WinForms.

        // ClientContext - Get the context for the SharePoint Site      
        ClientContext clientContext = new 
        ClientContext("http://SiteURL/sites/SP");  

        // Get the SharePoint web  
        Web web = clientContext.Web;  

        // Get the SharePoint list collection for the web   
        ListCollection listColl = web.Lists;  

        // Retrieve the list collection properties   
        clientContext.Load(listColl);  


        // Execute the query to the server.   
        clientContext.ExecuteQuery();  

        // Loop through all the list   
        foreach(List list in listColl)    
        {  
            // Display the list title and ID    
            Console.WriteLine("List Name: " + list.Title + "; ID: " + 
            list.Id);  
        }
1
  • It's exactly the same code as I posted above, but as you said, in console. – Wolwgang Aug 4 '17 at 9:40
0

Found it:

One of the lists in site was corrupted, and therefore unreadable. Deleting broken list fixed the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.