SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created a document library by code, and I need to return the URL of the All Items page.

I tried this, but its not what I am looking for

 SPList oSPList = oSPWeb.Lists.TryGetList(DocumentLibraryName);
                        if (oSPList == null)
                            Guid ID = oSPWeb.Lists.Add(DocumentLibraryName, DocumentLibraryName + System.DateTime.Now.ToString(), SPListTemplateType.DocumentLibrary);
                            oSPList = oSPWeb.Lists[ID];
                            DocumentLibraryLink = oSPList.DefaultViewUrl;
share|improve this question
up vote 2 down vote accepted

I'm guessing that you want the complete url to the Default view and not just the server relative url to the view. If that is true, you can do the following to get the easily get the full url.

DocumentLibraryLink = SPUtility.ConcatUrls(oSPWeb.Url, oSPList.DefaultView.Url);

The result is something like this


If the view is not the default view, you can use this. ViewName is the Display Name for the view.

DocumentLibraryLink = SPUtility.ConcatUrls(oSPWeb.Url, oSPList.Views[ViewName].Url);

This will give the url even if it is located in the FORMS folder.

share|improve this answer
efaultviewurl is dispform.aspx, I need the link to /Forms/Allitems.aspx. but I dont want to hardcode i – Esteban V Mar 21 '12 at 12:26
so is allitems the default view for this list? – Rich Ross Mar 21 '12 at 12:32
yes its always the default view. – Esteban V Mar 21 '12 at 12:44
this should work? DocumentLibraryLink = SPUtility.ConcatUrls(oSPWeb.Url, oSPList.Views["All Documents"].Url); – Esteban V Mar 21 '12 at 12:46
That worked for me in quick mock test on my development instance using an OOB document library. Also, if it is always the default view then DefaultView.Url returns the correct url in SP2010. this is a different property than DefaultViewUrl which returns the server relative path. – Rich Ross Mar 21 '12 at 12:47


share|improve this answer
defaultviewurl is dispform.aspx, I need the link to /Forms/Allitems.aspx. but I dont want to hardcode i. – Esteban V Mar 21 '12 at 12:22
That is strange I get /Forms/Allitems.aspx using that code – justforkix09 Mar 21 '12 at 13:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.