I have had many painful experiences attempting to deploy picture libraries with custom fields from Visual Studio with previous versions of SharePoint but with 2013 I have come up with this method (which may not be the best but seems to work consistently). With any luck this will aid someone else and save them the time I have wasted previously. This guide is for SharePoint 2013 and the solution is developed in Visual Studio 2013, I have not tested this method with any other combination so outside of this environment you’re on your own.
- Open Visual Studio 2013 and create and SharePoint 2013 – Empty Project
- Enter the name of the local URL of the SharePoint site you are going to test against, for this solution select Deploy as a sandboxed solution as there is no code required.
- As we are not developing any code for this solution set the project property Include Assembly in Package to False.
- Now we have our empty SharePoint project ready to go, in Solution Explorer right click the project name and select Add > New Item. Under the Office/SharePoint templates select List, give the list a name and click Add
- On the list settings screen select Create a customizable list template and a list instance of it. From the templates available in the drop down select Document Library
- All going well the list has been added to the project and schema designer window for the new list has opened. Currently this is the schema for a document library so the content type needs to be changed. Click the Content Type button
- In the Content Type Settings window right click the current default Document type and select Delete, in this example I also removed the Folder content type as it was not required
- Click in the empty Content Type Name box if it is not automatically selected for you and select Picture from the drop down list and click OK
- In the main window you can now see a different set of columns reflecting the content type change. In the solution explorer you can also see a bunch of files have been added under the list, select all the files under the list (not list instance) except Elements.xml (include Schema.xml, not selected in this screenshot) and delete them
- Next the files that were deleted need to be replaced with picture library ones. Right click the list name in Solution Explorer and select Add > Existing Item.
Next browse to the SharePoint 15 hive features and locate the Picture Library feature (default path):C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\FEATURES\PictureLibrary\Select all the files in the PicLib directory and click OK
- The screenshot below shows the above location and files contained in the PicLib directory in Windows Explorer
- The Solution Explorer list structure should now look as follows. Click the Show All Files button at the top of the Solution Explorer window, you should now see the SharePoint managed file SharePointProjectItem.spdata under the list definition, open it up
- The contents of the file should be similar to the one shown below. This file defines which files are included in the list feature when SharePoint packages the WSP solution, we need to adjust this to include the files we just added so they are deployed
- Copy the existing line and create a new entry for each file to be included.Note it is very important to make sure only the Elements.xml file has a type attribute of ElementManifest, all other files should have a type of ElementFile.You should end up with the file looking similar to the screenshot below
- Next open the Elements.xml file from under the list and update the ListTemplate Type attribute to 109 as shown (109 is the type of the Picture Library)
- Now open the Schema.xml file from under the list. Update the List attributes for Title and URL to exactly match the ListTemplate Name attribute from the Elements.xml file.
Add the EnableContentTypes attribute with a value of TRUE.
Finally Edit the ContentTypes node so it matches the screenshot shown. Note there will be an extra item required if folders are required
- The list definition is now configured, on to the list instance. Open the Elements.xml file and update the TemplateType attribute to 109 to match the list definition. At this point save everything that is open and close and reopen the Visual Studio solution, this is required for Visual Studio to pick up the changes we made to the SharePoint project item file we made earlier.Note if this is not done the new files will not be packaged and the feature cannot be activated.After closing and reopening you can make any customizations required to the list and add any custom field columns required using the schema designer. This can be opened by double clicking on the list name in Solution Explorer
- Once all customizations have been made you are ready to deploy and test the solution right click the project in Solution Explorer and select Deploy. Visual Studio will now build and package the solution and attempt to deploy and activate the feature on the SharePoint site defined at the start
- In your browser open the SharePoint site and navigate to the Site Contents, your list should be listed with a new! flag next to it, click the list
- Your Picture Library is now deployed and ready to go!