Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

2 Answers 2

up vote 1 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

http://servername/sitecollection/site/lists/listname/defaultpagename.aspx

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.

http://servername/sitecollection/site/lists/listname/forms/viewname.aspx
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

Try

SPUrlUtility.CombineUrl(oSPWeb.Site.Url,oSPList.DefaultViewUrl);
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

 
discard

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.