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

StackOverflow https://stackoverflow.com/questions/8838683

Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top