Question

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.

Was it helpful?

Solution 2

Found it:

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

OTHER TIPS

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);  
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top