How to create a site definition that creates a picture library and populates it with an image.

Ok so I had a fun week learning how site definitions really work.  Wow!  Very cool stuff, now I see why so many of you get lost in there and never come out.  Thankfully I am back to portal search problems next week and I can escape CAML and the 1,000 fleas that come with it. 

 

Before I return to the safety of SharePoint portal infrastructure, extranets, and taxonomy design I will leave you with three articles that are hopefully fresh ideas on things to do with the animal that can go weeks without water. 

 

So the request was to come up with a way to have the logo in the left hand corner of a WSS site display a logo from a picture library.  This way the users could just replace the file in the library to add their own custom logo to their site without using FrontPage.  I decided to tackle what I thought would be the hard part first.  How to modify the already custom site definition so that all future sites that are created would have this functionality.  We will worry about the existing sites later, in article # 3. 

 

After doing some googling I couldn’t find a good answer.  So I dove head first into the admin guide followed by the SDK and made up my own solution.  After looking at how the onet.xml file works I realized I need to create 3 new modules to create files and then have my configuration call those modules. 

 

So below the module

 

<Module Name="DefaultBlank" Url="" Path="">

….lots of xml

</module>

 

I created 3 new modules as so:

 

<Module Name="SiteImages" List="109" Url="SiteImages" Path="DOCTEMP\A">

            <File Url="wpd.gif" Type="GhostableInLibrary"/>

      </Module>

     

      <Module Name="SiteImages1" List="109" Url="SiteImages/_t" Path="DOCTEMP\A\t">

            <File Url="wpd_gif.jpg"/>

      </Module>

 

      <Module Name="SiteImages2" List="109" Url="SiteImages/_w" Path="DOCTEMP\A\w">

            <File Url="wpd_gif.jpg"/>

      </Module>

 

I will try to explain how the siteimages Module works.

 

<MODULE>

Name – This is the name of the module, you reference this in the configuration section to cause this section to be added.

List – In this case 109 is the code for Picture Library as defined earlier in the file

URL – This is where the files will be stored relative to the root of the site.

Path – This is where within the site definition it will retrieve the files from.  I created the A folder under the DOCTEMP at the root of the site definition.

 

<FILE>

URL – Is the name of the file within the site as it is located in the SiteImages folder.

Type – I don’t really understand this part but without it the file does not show up in the library even though it is there. 

 

I will not repeat for the other 2 modules but I will say this.  Notice each module has its own name, and the url and path is different for each.  The reason we need 3 modules is when you upload a picture to a picture library it not only uploads the file but it creates 2 preview images and puts them in hidden sub folders.  Well, for our picture library to have the preview functionality available when we automagically create it we need to populate these preview images also.

 

Now you are probably wondering how do you get these preview images?  What I did was go to an existing site and upload my image.  Then SharePoint created the preview images.  I copied them to my doctemp locations and I was good to go. 

 

Just to be clear my directory structure was

 

CustomSiteDef\DOCTemp\A\wpd.gif

CustomSiteDef\DOCTemp\A\t\wpd_gif.jpg

CustomSiteDef\DOCTemp\A\W\wpd_gif.jpg

 

And for some reason the 2 wpd_gif.jpg files were slightly different size.  I figured I would just give SharePoint what it wanted and went through the effort to have 2 separate files.

 

Alright so now we know how to create files and where to get the right files from we need to look for where to tell the file to use our modules.  For this we go up to the configuration section.

 

        <Configuration ID="0" Name="Default">

            <Lists>

………….. lots of xml cut out

            </Lists>

            <Modules>

                <Module Name="Default"/>

                <Module Name="WebPartPopulation"/>

            </Modules>

        </Configuration>

 

This is what it looks like by default.  We are just going to add reference to our 3 modules right below the module named “WebPartPopulation”

 

You should have something like this:

        <Configuration ID="0" Name="Default">

            <Lists>

….. Lots of cut XML

            </Lists>

            <Modules>

                <Module Name="Default"/>

                <Module Name="WebPartPopulation"/>

            <Module Name="SiteImages"/>

            <Module Name="SiteImages1"/>

            <Module Name="SiteImages2"/>

            </Modules>

        </Configuration>

 

So this will force SharePoint to add our modules if you choose Configuration 0.

 

Only thing left is to now create that Picture Library called SiteImages so our files have somewhere to go.  To do this we stay in the same configuration section.  We are just going to move up to the <Lists> section we removed earlier.  We will then just add another list item by inserting this code.

 

<List Title="SiteImages" Type="109" Url="SiteImages" />

 

And that’s all folks!  If you create the directories in doctemp and copy in the files, then make these changes to your onet.xml you will get a picture library with a picture in it next time you create a site.  And to make this easily reproducible I have included all of the files you would need.  Go to HERE you can download the new onet.xml file and the images so you can try this in your test enivornment.  I am also including a word document with the onet.xml text saved inside and all of the places where I added to the file are saved in green.  I know sometimes it is easier to look at the real thing than to follow goofy instuctions.

 

Next article will be how to change the default.aspx file so you can reference this image as your site logo.  Articel #2

 

Let me know what you think.

 

 

Shane

SharePoint Help from SharePoint911

Comments

# Using a picture from the library as your site logo in a site definition.

Thursday, February 09, 2006 11:25 AM by The SharePoint Farmer's Almanac

So in our last article on site definitions we discussed how to create a site definition that creates...

# Using a picture from the library as your site logo in a site definition.

Thursday, February 09, 2006 11:26 AM by The SharePoint Farmer's Almanac

So in our last article on site definitions we discussed how to create a site definition that creates...

# How do I add a preconfigured XML web part to a site definition? Part 1 of 3 on the road to sticky left hand navigation in SharePoint Portal Server.

Sunday, March 19, 2006 10:59 PM by The SharePoint Farmer's Almanac

So our 1st technical challenge to overcome from “The Road to Sticky Left Hand Navigation in SharePoint...

# How do I add a preconfigured XML web part to a site definition? Part 1 of 3 on the road to sticky left hand navigation in SharePoint Portal Server.

Monday, March 20, 2006 9:41 AM by The SharePoint Farmer's Almanac

So our 1st technical challenge to overcome from “The Road to Sticky Left Hand Navigation in SharePoint...

# re: How to create a site definition that creates a picture library and populates it with an image.

Wednesday, May 02, 2007 3:18 PM by Muhammad Masood

Hi, It is very good. The Type (GhostableInLibrary, Ghosting etc) specify whether WSS store files in content database or in file system. If you specify GhostableInLibrary = it means you are telling WSS to maintain in content database. Thanks.

# re: How to create a site definition that creates a picture library and populates it with an image.

Friday, September 07, 2007 3:19 AM by Vishan

Hi, i am using wss 3.0. I have created a picture library with over 10 pictures, but the page takes about 30secs to load. I had the pictures grouped into category.

I have now had to do an item limit so my picture library only shows 10 pics per page, so the page loads quicker. Does anyone know why this happens?.

Thanks,.

# re: How to create a site definition that creates a picture library and populates it with an image.

Friday, September 07, 2007 3:19 AM by Vishan

Hi, i am using wss 3.0. I have created a picture library with over 10 pictures, but the page takes about 30secs to load. I had the pictures grouped into category.

I have now had to do an item limit so my picture library only shows 10 pics per page, so the page loads quicker. Does anyone know why this happens?.

Thanks,.

Leave a Comment

(required) 
(required) 
(optional)
(required)