none
CSOM: List does not exist at site with URL RRS feed

  • Question

  • Hi all. I'm trying to manipulate some items in an SP 2013 library with CSOM.  I have a document library called Contracts.  I can see the library on my site through the UI. I can see the library in my SP 2013 Client Browser.  I can go into the library and see its contents.  However, when I try to get the list using CSOM with the following code, I get an error: List "Contracts" does not exist at site with URL: http://mysiteurl

    Here's the code, pretty standard:

    List targetList = context.Web.Lists.GetByTitle("Contracts");
    context.Load(targetList, l => l.DefaultViewUrl);
    context.ExecuteQuery();

    If I do the same thing with any number of lists in the site, I'm able to access them. When I look at context.Web.Lists, Contracts is just not in the collection.  Anyone know why this would be happening?

    Tuesday, July 16, 2019 7:21 PM

All replies

  • Hi Smith,

    First try to get the exact name of that list in the site & also we will make sure that list is displaying here or not. for that run the below C# Code.

    using (SPSite site = new SPSite("http://SiteUrl/"))
    {
      using (SPWeb web = site.RootWeb)
         {
            SPList list = web.Lists.TryGetList("My List");
            if (list != null)
            {
              Console.WriteLine("List exists in the site");
            }
            else
            {
              Console.WriteLine("List does not exist in the site");
            }
              Console.ReadLine();
         }
    }
    Thanks & Regards,


    sharath aluri


    Tuesday, July 16, 2019 7:37 PM
  • Hi gsmith,

    Please make sure the "Contracts" list exists in the site url passed in ClientContext object, I tested the code snippet it works as expected:

                ClientContext ctx = new ClientContext("http://sp/sites/dev");
                Web web = ctx.Web;
                List list = web.Lists.GetByTitle("Contracts");
                CamlQuery query = CamlQuery.CreateAllItemsQuery();
                ListItemCollection items = list.GetItems(query);
                ctx.Load(items, its => its.Include(item => item["Title"], item => item.Id));
                ctx.ExecuteQuery();
    
                foreach (var item in items)
                {
                    Console.WriteLine(item["Title"].ToString());
    
                }

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, July 17, 2019 1:49 AM
  • Your code looks correct.

    Please check the if the document library is available on same site whose URL you are using in your code.

    Also, check the display name of your document library is correct(no spelling mistake, maybe).

    --------------------------------------------------------------------------------------------------------------------

    Please Vote(^) and accept as an Answer if it helped you.

    Wednesday, July 17, 2019 6:47 AM
  • It definitely exists in the site, I can see it in the browser. I ran your code snippet and I get the same error.  It's very odd.  It exists on the site but CSOM code can't find it.  Perhaps the library is corrupt somehow.
    Wednesday, July 17, 2019 1:21 PM
  • Hi gsmith,

    How about creating a new library with another name for example "Contracts1" in the site and then accessing with CSOM code ? Did the issue still exist ?

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.


    Wednesday, July 17, 2019 1:53 PM
  • Hi gsmith,

    Have you tried other library, still the same issue in CSOM code ?

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, July 19, 2019 7:35 AM