views:

169

answers:

3

In Sharepoint 2007/ 2010 not sandboxed you could place images/css/javascripts etc. somewhere in Sharepoint root folder or in wpresources folder.

What is a good/working place to put these files in sandboxed solutions?

A: 

You can always add them to your DLL as embedded resources

Vladi Gubler
+1  A: 

Either:

  1. Use a site collection library like Style Library, Site Assets, Site Collection Images, or a custom Asset Library, Picture Library, or Document Library.
  2. Create a separate farm solution that contains the static, client side files. These files should have no impact on server performance so a farm solution might be approved by server administrators as long as they do not overwrite or interfere with OOTB files.
Rich Bennema
Good suggestion, just wanted simpler solution than with specific libraries.
Voyta
A: 

The goal was to have something resembling the usual structure with folders, subfolders, where you can just drop images and other client side files and reference them by relative url.

And at the end the solution was to create a module with files, which is fairly easy in Visual Studio 2010 - Add new item -> Sharepoint -> Module.

Then you can just create/drop files/folders there, and the files list in elements.xml is maintained by Visual Studio. They are not included in any library, but can be referenced and loaded as needed.

One important thing is to give the module unique name or add Url attribute (which is url prefix), so that it would not conflict with files from other solutions.

You reference files then using

web.ServerRelativeUrl + "/YourModuleName/yourfile"

Or, if you specified Url in elements.xml (<Module Name="YourModuleName" Url="YourUrl">)

web.ServerRelativeUrl + "/YourUrl/YourModuleName/yourfile"

If you deploy feature with module at a web scope, web is SPContext.Current.Web, and at a site scope it is SPContext.Current.Site.RootWeb

And if there is a need to actualy get contents of the file, you can do that with

web.GetFile("YourModuleName/yourfile")

An article on including javascript files in particular, which uses module here.

Voyta