Wednesday, December 3, 2008

Deploying a file to the "_layouts" folder

I don't like to feel stupid. At all. But sometimes it is a wonderful feeling, because sometimes it means "Shit, how could I have missed this simple solution?".

In my current project, we've had an issue with deploying to SharePoint's _layouts folder. Using a module in the Elements.xml file only creates a ghosted database copy which won't work for example a custom login page, which is what I wanted to deploy.

Now, at this small conferance in Malmö, Sweden, I met Tobias Zimmergren who said something along the lines of "But why don't you just use the RootFiles-element in your manifest.xml file? I do that all the time.".

So, yea, I felt stupid sure, but... The next day I also had an auto-deployed custom login page to the _layouts-folder. :-)

The code is very easy...

In your xyz.ddf-file you'll put something along the lines of:
.Set DestinationDir="Layouts"
Features\XyzSecurity\Page\XyzLoginPage.aspx

In your manifest.xml you'll write something similar to:
<TemplateFiles>
<TemplateFile Location="Layouts\XyzLoginPage.aspx"/>
</TemplateFiles>

Very nice!

3 comments:

[MVP] Tobias Zimmergren said...

Glad I could help :-)

Anonymous said...

If you are using Visual Studio & VSeWSS you can't modify the manifest.xml file directly. You have to add a new "Root file" SharePoint item into you project. Then create subfolders under the rootfiles directory that has been created in your Visual Studio project, to replicate the 12 Hive structure. Typically : Rootfiles\TEMPLATE\LAYOUTS\...

When the subfolder structure is ready, use the "add" option in Visual Studio to place the file into the appropriate subfolder.
Deploy the project... you will find the file at the right place in the /12 Hive ...

Terborn said...

Great, thanks for the tip! :-)