Friday, January 30, 2015

Create Custom Picture Library with List Definitions through Visual Studio

One of the major problem we faced when we try to create a picture library through a visual studio that, there is no any Definition type called picture of library, but we can add instance file based on picture library template. if we got a requirement to add a custom columns like we do in normal browser window through a list settings, simply we cannot do through a VS project as we cannot add fields in to a element file.  

When I faced kind of a situation where I need to add Lookup filed in to a Picture Library I did some research and found a one way to do it. here are the steps.

1) Create a Site column ( LookUp Field as follows )

 <Field
       ID="{63F1697D-35B8-40C0-BE33-6CCB44AD35AE}"
       Name="DPMCExternalLink"
       DisplayName="DPMC External Link"
       Type="Lookup"
       List="Lists/ExternalLink"
       ShowField="Title"
       Required="TRUE"
       Group="DPMC Site Columns">
  </Field>

Then create a Content type based in picture content type and added the above mentioned lookup filed in to the content type [ Note : you can added only site columns to the content type ]



[ Note : The feature which deploy  content type ans site column need to be as a site feature ]

2) After that  Create a List and select "Document Library" in SharePoint Customization Wizard window. then click content type button and delete document content type which was the default one and added you newly created content type then make it as a default content type. 






3) In the Library you can see some files been added along with the Instance module, Schema, and Element files. most of them are aspx and htlm file please remove all the aspx and html file. from the library.

4) Then navigate to the 15 hive folder.  TEMPLATE  > FEATURES > PictureLibrary > PicLib
[C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\FEATURES\PictureLibrary\PicLib]

copy all the aspx and html file then past it into the library. Then set those files Deployment Type as ElementFile.




5) Open schema file of the Picture library and add following fields / tags in to following positions.

ThumbnailSize="160" WebImageHeight="480" WebImageWidth="640" into the "<List xmlns:" tag.
Then <Folder TargetName="Forms/Picture" /> into the Defult content type.



Open Schema.xml  File in the 15 Hive [ \15\TEMPLATE\FEATURES\PictureLibrary\PicLib ] then copy Views and Forms sections from there and replace those in our Schema file . 

Then in the element file  do following changes
Type = "109" [need to change instance element file also]
Sequence = "210"
DocumentTemplate = "100"




ok That's It ... 
HAPPY CODING

2 comments:

  1. Thanks for your solution. For multiple picture libraries you need to add separate features.

    ReplyDelete
  2. I have done exactly like post except creating the lookup field, the solution could not activate the feature anymore and this error message has appeared "Error occurred in deployment step 'Activate Features': Cannot complete this action. "

    ReplyDelete