I would like to add the following feature to my Web Template. - Add a picture library with some default pictures in it

First step would be creating a custom list from the type picture library. But how would you be able to add some pictures (items) to this library?


Create a module, call it e.g. Pictures and add pictures to it. The elements.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="Pictures" Url="MyPictureLibrary">
    <File Path="Pictures\pic1.png" Url="pic1.png" Type="GhostableInLibrary"/>
    <File Path="Pictures\pic2.png" Url="pic2.png" Type="GhostableInLibrary" />

Add the module to a web scoped feature. (Assuming you call your library MyPictureLibrary and the feature that deploys this module is activated in the same web as the library)

Edit: Or do it through code like Rob suggested.


Once you have you're library created, you could use:


To add the files to the root folder of the library. The Add method has numerous overrides depending on how you want to add the file (byte array versus stream, with or without metadata, etc.)

I can provide a more complete code snippet if needed...let me know.

  • Rob, thanks for your answer but I'm looking into a solution where this can be done as part of my List Instance process. I don't know if there are some options through the element.xml file to include files which were provisioned to e.g. an image folder under the _layouts folder? If the only option is code behind It would be nice to have some more details as you propsed. Thanks in advance! – Wim Hill Aug 2 '11 at 14:09
  • If you want to do it as part of the element.xml then tarjeieo's answer is the right way to go. From a code standpoint, you can create the list in a feature receiver and then add the files as noted above. – Rob D'Oria Aug 2 '11 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.