Moved

This blog is no longer maintained. All the content has been moved here: http://byteloom.marek-mierzwa.com

Friday, 20 January 2012

Custom upload form for document library in SharePoint 2010 - programmatic approach

As I wrote previously the one of my recent projects was to create a new upload page for specific Document Library (based on custom list template) that will use Telerik Upload component (Silverlight) and will entirely replace OOB upload.aspx page. Looking for some suggestions how to do this I found few solutions but none of them met my criteria:
  1. Using SharePoint Designer for customizing default upload page - I'm not sure if this could apply to document library; I also rejected this option from start as non-programmatic approach because of problems in future development and maintenance
  2. New document template redirection trick - looks simple but this wasn't enough elegant solution for me (I know - who cares, it's SharePoint after all... ;-)
  3. Creating a custom action in ribbon and hiding the old one with javascript - the first part looks quite nice but the second is another hack; also, "Add new document" link at the bottom of default document library view still points to the standard /_layouts/Upload.aspx page...
  4. Creating a custom action in ribbon with custom rendering template for ribbon - very nice solution when you want to change upload pages for all lists on farm, but this is not applicable in my case; still "Add new document" link at the bottom remains
There were also other approaches like changing all related links with jQuery on client side but I would prefer some simple, elegant and server side solution that will not cause any problems on migration to the next version of SharePoint.

Wednesday, 18 January 2012

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

Few days ago I faced with the problem of linking to default view page of custom document library (for purposes of redirection with Source parameter after uploading new document and filling it's meta data form).
At first I tried using SPList.Forms collection indexed with PAGETYPE enumeration as I found in article "How To Always Link to the Right Application Pages". But every time I was trying to get the default view object this way:

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


I was getting the following exception:

ArgumentNullException: "Value cannot be null. Parameter name: formType"
Fortunately this was working fine:

var defaultViewUrl = string.Format("{0}/{1}", documentLibrary.ParentWeb.Url, documentLibrary.DefaultView.Url);


I've checked that SPList.Forms collection returns valid forms/pages objects only for these three values:
  • PAGETYPE.PAGE_DISPLAYFORM
  • PAGETYPE.PAGE_EDITFORM and 
  • PAGETYPE.PAGE_NEWFORM
For every other it throws arg null exception as described above. This looks definitely like a bad design in Sharepoint API (one of many...) - the collection should be indexed with other enum that contain valid set of values.

You can find some more detailed info about the reason of this strange behavior on the short stackoverflow thread started by my question. How Stefan figured out that error is caused by enum to string conversion? I guess this mystery was revealed with ILSpy or some similar tool ;-)

Hello world!

Welcome on my new blog (and also the first one).
In few days I plan to picture some of my first experiences with development in SharePoint 2010. They are related with my current project - custom upload form with Telerik upload control (Silverlight) that will entirely replace the standard OOB upload mechanism for custom document libraries.