Saturday, June 5, 2010

Add New Files To 12-Hive Through A SharePoint Solution

As we got our SharePoint environment up and running, we needed to have the ability to make changes to our 12-Hive. We also wanted to have the flexibility to undo the changes and restore the 12-Hive to the way it was originally.

This post discusses the scenario where you need to add new files to the 12-Hive that do not already exist, such as new images or layouts. I call this solution HiveAdditions. If you have a need to update files that already exist in the 12-Hive, check out my other article Update 12 Hive Through A Feature. I call that solution HiveUpdates. We decided it would be best for us to separate these two types of Hive changes into two separate solutions.

This solution, HiveAdditions, simply allows us to add files into the 12-Hive upon a deployment. When we retract this solution, it simply removes all those files. We liked this approach because it allows us to have this solution as the one place for all new 12-Hive files. If we needed to add new files, we retract this solution, add the new files to the solution, then deploy it again.


1. In Visual Studio 2008, File -> New -> Project

2. Under Visual C#, pick SharePoint, then Empty

3. For Name, type: HiveAdditions

4. For Location, type: D:\development

5. Click OK

6. Select Full Trust (Deploy to GAC) and click OK

7. In Solution Explorer, right-click project HiveAdditions, then click Add -> New Items... -> SharePoint -> Root File

8. Leave Name alone and click Add

9. Under RootFiles (which now appears in Solution Explorer), delete RootFile1

Under RootFiles, we must mirror the 12-Hive locations where we want to add the new files.

Let's add image files under TEMPLATE/IMAGES.

10. Right-click RootFiles, click Add -> New Folder and name it TEMPLATE.

11. Right-click TEMPLATE, click Add -> New Folder and name it IMAGES.

12. Drag and drop your images into IMAGES folder. Be sure to right-click newly added files and click Include In Project if they are not already included.

13. Verify your manifest was created correctly. Click View -> Other Windows -> WSP View. Under HiveAdditions, you should see manifest.xml, then under that, RootFiles -> TEMPLATE -> IMAGES followed by the files you added. Double-click manifest.xml and verify your file paths are under TEMPLATE\IMAGES\file1.jpg, etc.

14. click Build -> Rebuild Solution

15. click Build -> Package Solution

The solution package that you just created in the above step, HiveAdditions.wsp, was created in your project's bin\debug folder.

To deploy the solution:

16. create folder d:\deploy

17. copy HiveAdditions.wsp from project's bin\debug folder to d:\deploy

18. In d:\deploy, create two batch files, add_hiveadditions.bat and remove_hiveadditions.bat.

add_hiveadditions.bat:
c:

cd\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN

stsadm -o addsolution -filename d:\deploy\HiveAdditions\HiveAdditions.wsp

stsadm -o deploysolution -name HiveAdditions.wsp -immediate -allowGacDeployment

d:
remove_hiveadditions.bat:
c:

cd\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN

stsadm -o retractsolution -name HiveAdditions.wsp -immediate

pause

stsadm -o deletesolution -name HiveAdditions.wsp

d:
19. in d:\deploy, type add_hiveadditions.wsp and hit enter

20. verify solution was deployed in Central Administration -> Operations -> Solution Management

21. verify files were added to 12-Hive!

1 comment:

  1. Hi!

    Good article! Thanks for sharing! I had the same problem, but managed to fix it using changes to MyFeature.Template.xml, per http://msdn.microsoft.com/en-us/library/ff798298.aspx#InsideSP14_Ch2_FUEIS2, section "Updating a Feature Definition with Upgrade Actions".

    Any thoughts on this? Is your method applicable in more situations?

    - Rogier

    ReplyDelete