Tuesday, October 19, 2010

Adding Pictures to a Picture Library via a VS2010 Module

Scenario
  • You would like to add some Images to an existing Image Library in your SharePoint site using a Visual Studio 2010 SharePoint Project.
  • You do this by following these steps.
    • Add a module to the project
    • Rename the module to the Image Library name
    • Set the module tag's url and path properties to the Image Library name
      • Leaving spaces in place
      • Ex: <Module Name="Recipe Pics" Path="Recipe Pics" Url="Recipe Pics">
    • Add the images to the module using Visual Studio Solution Explorer's "add existing item" option
    • Add the Type="GhostableInLibrary" tag to the Elements.xml tag for each image
      • Ex: <File Path="FriedOkra.jpg" Url="FriedOkra.jpg" Type="GhostableInLibrary"/>
    • Run the project to deploy the solution
      • This should run without errors
Issue
  • The images are in the Image Library, but the thumbnails on the list view and the item views are missing.  The Item view displays icjpg.gif instead.
  • This issue is also documented on Eugene Rosenfeld's blog.
Resolution
  • Check-out and check-in each image you just added
    • This creates the appropriate thumbnails, but this is a manual process and will be wiped out next time you redeploy the module
    • One option is to add a feature that will check out and in each image.  An alternative is to add the thumbnails directly to the module, although this has 1 issue as outlined below.
  • To add the thumbnails to the module, follow these steps
    • On the Image List's default view page you should see the "t" thumbnails for your images
      • Save each "t" thumbnail to disk in an "_t" subfolder
      • Replace any Html Encoding with the original characters
        • Change %20 to a space 
    • Click on each image's view page and you should see the "w" thumbnail
      • Save each "w" thumbnail to disk in an "_w" subfolder
      • Replace any Html Encoding with the original characters
        • Change %20 to a space
      • Issue: The "_w" images do not work correctly in 2010 with this method.  They are uploaded, but the default item view will not display them.
    • Add _w and _t folders to your module in Visual Studio
    • Add existing items to each module folder from the above subfolders
    • Add the Type="GhostableInLibrary" tag to the Elements.xml tag for each thumbnail image

No comments:

Post a Comment