I have some methods using CSOM that are being called form an external program. In one of these methods I check if a document set exists on a certain location, and if it does I want to return the url to the document set homepage for that document set.

I've manage to get the url down to this structure to get a working url:


With querying several properties of the web etc, I could dynamically get the contenttypename, url etc.

I'm just wondering if there's no easier path to get an url to the document set.

Also I would a suggestion to get rid of the DocumentSetName in the url to open the page. If it would work with only providing an id, that would be great.


Best way to build URL for document set homepage dynamically use this built-in page:

http://<websiteurl>/_layouts/15/DocSetHome.aspx?id=<server relative url of document set>

This SharePoint page will redirect you to correct document set homepage. You can get url of the document set using FileRef indexed property of SP.ListItem object.

Example, http://site/web/_layouts/15/DocSetHome.aspx?id=/site/web/library/docset1

Alternatively, you could can treat document set as folder and build link to folder url, like http://site/web/library/docset1 of the document set. Generally SharePoint will handle this and redirect you to document set home page instead of default view. Although I have noticed that this way is not very reliable if you have deeper folder structure in your document library.


This is the code I've got so far:

Web web = context.Web;
context.Load(web, w => w.Url);

List list = web.Lists.GetByTitle(listName);
context.Load(list, l => l.Id);

var items = list.GetItems(createGetDocSetQuery(query));
context.Load(items, folders => folders.Include(
    folder => folder["ID"],
    folder => folder["ServerUrl"],
    folder => folder["FileRef"]
count = items.Count();
if(count == 1)
    url = web.Url + "/documenten/Forms/ContentTypeName/docsethomepage.aspx?ID=" + items[0]["ID"];
    url += "&RootFolder=" + Uri.EscapeDataString(items[0]["FileRef"].ToString());

I'm wondering if there's a better way.

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.