I have been asked a lot if this feature is compatible with SharePoint 2013 so to make your life simple (and mine too I guess) I have migrated the Visual Studio 2010 (SharePoint 2010) solution to a Visual Studio 2012 (SharePoint 2013) solution. You will find here the solution and here the wsp.
Note: I got rid of the image because I couldn’t find quickly how to display in in the SharePoint 2013 ECB (not even sure if it is still possible)
When I started using the Document Sets feature I was surprised to see that you can not move a file to an existing Document Set, at least not easily.
In fact, you have the same issue if you wish to move a document into a folder. There is no easy way to do it. Well you have the Send To Other Location but how less user-friendly could it get? You do not get to select anything, you must know the destination URL…
…but anyway it’s not going to move the document but to copy it which is not what I want to do.
I came up with my own solution which will provide another menu item in the ECB (EditControlBlock) allowing the user to move a file to a document set.
the SharePoint project is made of 2 essentials things:
- A Custom Action Move to Document Set
- an Application Page ChooseDocumentSet which allows the user to select the document he wishes to move the document into.
1. Move to Document Set Custom Action
Sequence = “0” sets the Custom Action at the top of the menu.
RegistrationType = “ContentType” and RegistrationId = “0x0101” will make the Custom Action only visible for the Document.
Rights = “EditListItems” will make the Custom Action only visible for people who have Editing rights.
The rest of the Custom Action is pretty self-explanatory, I call our Application Page in a modal dialog using the Dialog capabilities of SharePoint.
2. ChooseDocumentSet Application Page
For the server side code, I’m using the MVP Pattern (model-view-presenter), so you will find the main logic of the code in the Presenter of the ChooseDocumentSet page.
Here are the two main methods:
– in the OnViewLoaded() method:
I check first if I am not already in a document set, if it’s the case, I get its name.
In the second part, I get recursively the list of document sets existing in the current list, I exclude the current document set if it’s the case.
Note that ParentFolderIsDocumentSet() and GetDocumentSets() are both Extensions Methods defined in a separate class that I will not explain here.
– in the OnSubmitClick() method:
This is where I actually move the document using the SPFile.MoveTo method. It’s the same method you would use to move document within a folder for instance.
In fact, a Document Set is an object which derived from a SPFolder.
You will find the Visual Studio Solution (SP2010) here.