SharePoint Online & DefaultDocumentLibrary in CSOM: The file |0 does not exist.

In my latest adventures with SharePoint Online & the Office Graph, I came against a peculiar undocumented exception.

It occurs when executing the following SharePoint Online CSOM code:


using (var context = new ClientContext(url))
{
    context.Credentials = // Your creds
    Web web = context.Web;
    List list = context.Web.DefaultDocumentLibrary();
    context.Load(web, w => w.Title);
    context.Load(list, l => l.Title);
    context.Load(list, l => l.RootFolder.ServerRelativeUrl);
    context.Load(list, l => l.RootFolder);
    context.Load(list, l => l.RootFolder.ParentFolder.ServerRelativeUrl);
    context.ExecuteQuery(); // Exception occurs here
}


The error message is:

The file |0 does not exist.

The stack trace doesn’t teach us anything useful. It only happens when the URL is a site which doesn’t have a default document library, like a blog site. I reproduced this in several SPO tenants with the same behaviour.

So, an extra check on the exception message an exception occurs would be necessary as a workaround. In that case, I’m not interested in the default document library anyway if there isn’t any.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s