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="" xmlns:xsd="" SolutionId="00000000-0000-0000-0000-000000000000" ResetWebServer="True" xmlns="">
  <Assembly Location="WebPartResources.dll" DeploymentTarget="GlobalAssemblyCache">
    <SafeControl Assembly="WebPartResources, Version=, Culture=neutral, PublicKeyToken=6763c0814d065309" Namespace="WebPartResources" TypeName="*" Safe="True" />
    <ClassResource Location="testfile.gif" FileName="testfile.gif" />

After deployment these files are located here.
For assemblies in GAX: C:\Program Files\Common Files\Microsoft Shared\web server extensions\wpresources\WebPartResources\\testfile.gif
For assemblies in BIN: C:\inetpub\wwwroot\wss\VirtualDirectories\80\wpresources\\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:



Name Description
Source Files


  • Torsten Mandelkow

Version history

  • 1.0 Initial Recipe