Question

I'm adding a very simple XsltListViewWebPart to an application page. Like so:

XsltListViewWebPart lvWebPart = new XsltListViewWebPart { ChromeType = PartChromeType.None, ListUrl = "/somesite/list" };
Page.Controls.Add(lvWebPart);

Everything works fine (I can download files, create folders, choose different views, etc.) - but the links of folders have the wrong href: they always point to the root web!

See these examples: enter image description here

As you can see, the document correctly links to ../sites/sr/doclib/mydocument.docx however when looking at the folders they forget the context they are currently in (they are in http://../sites/sr/_layouts/../../..Detail.aspx?RootFolder=..., the important part being /sites/sr/). They try to go to the _layouts folder in the root site collection context -as shown above: http://../_layouts/../../..Detail.aspx?RootFolder=...

Or again summarized:

  • The application page location:
    • http://sp/sites/sr/_layouts/my/application/Detail.aspx
  • The list/doclib I'm accessing
    • http://sp/sites/sr/mylist
  • The URL for folders inside XsltListViewWebPart
    • http://sp/_layouts/my/application/Detail.aspx?RootFolder=...
  • The URL for folders as they should be
    • http://sp/sites/sr/_layouts/my/application/Detail.aspx?RootFolder=...

Here comes the kicker: When using a ListViewWebPart, everything works like it should! So instead of the XsltListViewWebPart above I just use a ListViewWebpart - and folders work, the context is taken into account the the folders have the URL like I want (http://../sites/sr/_layouts/../../..Detail.aspx?RootFolder=...

I tried setting the WebId Property on the XsltListViewWebpart hoping it would set the context, but no luck. I'm now thinking that either I configure it wrongly or the new SharePoint 2010 XsltListViewWebPart has a bug - as the same code works for a ListViewWebPart on the same Application page.

I hope somebody can verify this issue.

Was it helpful?

Solution

In brief, just don't use XsltListWebPart on Application Pages.

And here are some summarized explanations:

XsltListViewWebPart and other OOTB SharePoint webparts (especially complex ones), apparently just aren't supposed to work in Application Pages environment. In other words, they weren't tested there and thus their operability is not guaranteed.

This can be indirectly confirmed by reading at least the following MSDN articles:

.. A site page can also host features such as dynamic Web Parts, and Web Part Zones. Application pages cannot do these things.

Also it is stated in MS course 10232.

Concerning XsltListViewWebPart (XLV) in particular, I heard of multiple problems while using it from Application Page, and experienced some of them myself.

For example, if you customize XLV using XslLink property, XLV will fail to cache the xsl file, and as a consequence, ECB and corresponding buttons on Ribbon will not work. In logs, you will get the following exception message:

Attempted to use an object that has ceased to exist.

Also, you can check out the following question for another example of problems with OOTB webpart on application page (ListViewWebPart, this time):

OTHER TIPS

First, I think Andrey hit the nail on the head. In addition, you could try to use the ListViewByQuery control on an application page if you are looking for a simple tabular layout of data (i.e. a list). Microsoft does this in the OOB workflow status page (i.e. _layouts/wrkstat.aspx) for display of tasks.

I've not tried it with ECB menus and such, but did use it for Read-Only lists of data. Since it sounds like you are using it for a Document Library with Folders, I am not confident in it working right without lots of code to get folders, sorting, and paging working correctly. It might be worth a shot, though I wouldn't spend much time with it as the Site Page is probably a better way to go with less custom code.

If you go with ListViewByQuery, be sure to review these links for paging, etc:

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top