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?
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?
Either:
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.