Error: "Value cannot be null. Parameter name: formType" retrieving default view page of document library

3.2k views Asked by At

I'm trying to get the default view url of standard document library list in SP2010:

var defaltViewUrl = documentLibrary.Forms[PAGETYPE.PAGE_DEFAULTVIEW].Url;

and I'm constantly getting the following exception:

ArgumentNullException: "Value cannot be null. Parameter name: formType"

while PAGETYPE.PAGE_DEFAULTVIEW enum value is definitely not null. Any ideas what am I'm doing wrong?

1

There are 1 answers

1
Stefan On BEST ANSWER

The default view of a list is not stored in the form collection (SPList.Forms).

So you indeed have to get the url of SPList.DefaultView.Url:

string absViewUrl = SPUrlUtility.CombineUrl(web.Url, documentLibrary.DefaultView.Url);

The ArgumentNullException occurs since SharePoint is converting the PAGETYPE.PAGE_DEFAULTVIEW to string. Since PAGE_DEFAULTVIEW is not a valid form it's converted to null.