Add Class Resource Files

This recipe allows to add a file which should be deployed as class resource file for an assembly.

Recipe Description

Class resource files are added to the project in folder 80/BIN/wpresources/[NameOfAssembly]. In manifest.xml these files are deployed to

<Solution xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SolutionId="00000000-0000-0000-0000-000000000000" ResetWebServer="True" xmlns="http://schemas.microsoft.com/sharepoint/">
 <Assemblies>
  <Assembly Location="WebPartResources.dll" DeploymentTarget="GlobalAssemblyCache">
   <SafeControls>
    <SafeControl Assembly="WebPartResources, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6763c0814d065309" Namespace="WebPartResources" TypeName="*" Safe="True" />
   </SafeControls>
   <ClassResources>
    <ClassResource Location="testfile.gif" FileName="testfile.gif" />
   </ClassResources>
  </Assembly>
 </Assemblies>
</Solution>

After deployment these files are located here.
For assemblies in GAX: C:\Program Files\Common Files\Microsoft Shared\web server extensions\wpresources\WebPartResources\1.0.0.0__6763c0814d065309\testfile.gif
For assemblies in BIN: C:\inetpub\wwwroot\wss\VirtualDirectories\80\wpresources\1.0.0.0__6763c0814d065309\testfile.gif

In code you can access there files:

SPWeb currentWeb = SPControl.GetContextWeb(Context);
Type currentType = this.GetType();
string classResourcePath = SPWebPartManager.GetClassResourcePath(currentWeb, currentType);  
image = new Image();
image.ImageUrl = classResourcePath + "/testfile.gif";

The file could also be access via URL:

http://servername/_wpresources/[assemblyname]/testfile.gif

Arguments

Name Description
Source Files

Authors

  • Torsten Mandelkow

Version history

  • 1.0 Initial Recipe