2
votes

I am trying to retrieve all items from a SharePoint 2013 Video asset library using the CSOM in C#. When I run my console application I occasionally receive the following error:

Microsoft.SharePoint.Client.ServerException: A list, survey, discussion board, or document library with the specified title already exists in this Web site.  Please choose another title.

I searched for the error, but the issues I found were with creating the list or updating items. I am only trying to retrieve the items. The library loads just fine in a browser. Also, I have a webpage that runs the same code as my console application and that does not throw an exception. Here is the block of code that throws the exception:

ClientContext context = new ClientContext(SharePointURL);

                List AssetList = context.Web.Lists.GetByTitle(SharePointListTitle);

                context.Load(AssetList);

                CamlQuery query = CamlQuery.CreateAllItemsQuery();
                ListItemCollection items = AssetList.GetItems(query);

                //Retrieve all items in the ListItemCollection from List.GetItems(Query). 
                context.Load(items,
                    itms => itms.Include(
                        i => i["GUID"],
                        i => i["Title"],
                        i => i["FileLeafRef"],
                        i => i["FileRef"],
                        i => i["VideoSetDescription"],
                        i => i["Live_x0020_Date"],
                        i => i["Expiration_x0020_Date0"],
                        i => i["Is_x0020_Active"],
                        i => i["Tags"],
                        i => i["AlternateThumbnailUrl"]
                        )
                    );

                context.ExecuteQuery();
1

1 Answers

1
votes

I'm on mobile right now so I can't easily test this for you but I believe you need to do a context.ExecuteQuery() after loading AssetList as well.

This would then make your source:

ClientContext context = new ClientContext(SharePointURL);

List AssetList = context.Web.Lists.GetByTitle(SharePointListTitle);

context.Load(AssetList);
context.ExecuteQuery();

CamlQuery query = CamlQuery.CreateAllItemsQuery();
ListItemCollection items = AssetList.GetItems(query);

//Retrieve all items in the ListItemCollection from List.GetItems(Query). 
context.Load(items,
    itms => itms.Include(
        i => i["GUID"],
        i => i["Title"],
        i => i["FileLeafRef"],
        i => i["FileRef"],
        i => i["VideoSetDescription"],
        i => i["Live_x0020_Date"],
        i => i["Expiration_x0020_Date0"],
        i => i["Is_x0020_Active"],
        i => i["Tags"],
        i => i["AlternateThumbnailUrl"]
        )
    );

context.ExecuteQuery();

Let me know if this isn't the case and I'll pull up a project where I've done something similar once back on a desktop.