Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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" />
  </Module>
</Elements>

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.

share|improve this answer
    
Thanks Tarjeieo! –  Wim Hill Aug 2 '11 at 14:38
add comment

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

SPList.RootFolder.Add(...)

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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