How to include Pictures when your site is created
This can be achieved using a feature or as part of the onet.xml file for a site definition. I will use a feature as this is my preferred approach and it can also be reused across multiple sites.
1. Create feature
Create a new directory under the 12 hive, and create two new files feature.xml and elementManifest.xml (you can copy from an existing feature to make this easier).
Edit the feature file and add the contents as below, this will be the basis of the feature. You will need to provide a unique GUID. Use guidgen from Visual Studio to generate you GUID.
<Feature Title=”Add Picture Feature” Id=”21BC0000-805F-4151-A41C-5FE5B66ACBDA”
Description=”Add Picture Demo” Version=”1.0.0.0″
Scope=”Web” Hidden=”TRUE” DefaultResourceFile=”core”
xmlns=”http://schemas.microsoft.com/sharepoint/”>
<ElementManifests>
<ElementManifest Location=”elementManifest.xml” />
</ElementManifests>
</Feature>
2. Create a subdirectory under the feature folder
When you upload an image to a picture library SharePoint creates two additional versions of that image in JPEG format that it displays in the thumbnail and preview screens. When adding images we need to also add these and they will be renamed with a .jpg extension as shown:
MyPicture.gif -> MyPicture_gif.jpg
MyPicture.jpg -> MyPicture_jpg.jpg
Create a subdirectory below the feature called “Picture Library” and then create two folders beneath this call “t” and “w”.
| Tip: Upload the image to an existing library to generate the thumbnail and preview images. |
This will give you a directory structure similar to this
Copy the original image to the “Picture Library” directory, and the thumbnail and preview images to the “t” and “w” sub directories respectively.
3. Add the files to the feature.xml and elementManifest.xml files
feature.xml
Add the images files to your feature.xml file as below.
<Feature Title=”Add Picture Feature” Id=”21BC0000-805F-4151-A41C-5FE5B66ACBDA”
Description=”Add Picture Demo” Version=”1.0.0.0″
Scope=”Web” Hidden=”TRUE” DefaultResourceFile=”core”
xmlns=”http://schemas.microsoft.com/sharepoint/”>
<ElementManifests>
<ElementManifest Location=”elementManifest.xml” />
<ElementFile Location=”Picture Library\21appsLogo_large.jpg” />
<ElementFile Location=”Picture Library\w\21appsLogo_large_jpg.jpg” />
<ElementFile Location=”Picture Library\t\21appsLogo_large_jpg.jpg” />
</ElementManifests>
</Feature>
elementsManifest.xml
The elements manifest file defines the picture library we are creating and the source and target for each of the files.
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
<ListInstance FeatureId=”00bfea71-52d4-45b3-b544-b1c71b620109″ TemplateType=”109″ Title=”Picture Library” Url=”Picture Library” />
<Module Name=”PictureLibrary” List=”109″ Url=”Picture Library” Path=”Picture Library”>
<File Url=”21appsLogo_large.jpg” Type=”GhostableInLibrary” />
</Module>
<Module Name=”PictureLibrary1″ List=”109″ Url=”Picture Library/_t” Path=”Picture Library\t”>
<File Url=”21appsLogo_large_jpg.jpg” />
</Module>
<Module Name=”PictureLibrary2″ List=”109″ Url=”Picture Library/_w” Path=”Picture Library\w”>
<File Url=”21appsLogo_large_jpg.jpg” />
</Module>
<Module Name=”Remainder” Url=”" Path=”">
</Module>
</Elements>
Note: three modules are used as the URL (path) the files are copied from and to are different.
The thumbnail and preview images are located in /_t and /_w folders within a picture library.
In this example we have also created the picture library in which we will add the picture
<ListInstance FeatureId=”00bfea71-52d4-45b3-b544-b1c71b620109″ TemplateType=”109″ Title=”Picture Library” Url=”Picture Library” />
4. Install the feature
Using stsadm.exe install the feature
stsadm -o installfeature -name AddPictureFeature
In our example we have hidden the feature (Hidden=”True”) as we will add this directly to a sites onet.xml file so that it is created upfront. This is often referred to as Feature Stapling.
5. Update the site defintions onet.xml
In this example I will add the feature to the STS site definition,
Warning – it is always recommended to make copies and change these as future service packs may overwrite your changes and you could effect you support.
Add the feature to the <WebFeatures> section of the sites onet.xml. Depending on your site definition you may need to add this to multiple configurations.
<!– Add Picture Feature –>
<Feature ID=”00bfea71-52d4-45b3-b544-b1c71b620109″ />
6. Recycle and Create the site
Do an IISreset (as your doing this in dev, aren’t you!) and create a new Team Site (or the site you altered).
7. Create a site test
After creating the site you should now see a Picture Library with one image automatically included.
Clicking on the library should show your image with the thumbnail.
Hope this is of some help, it’s fairly basic stuff but sometimes these simple things are easily forgotten.



