SharePoint / ASP.Net Development
Experiences from the field...
Navigation
   RSS 2.0
Categories
Entries by Month

# Thursday, January 27, 2005

If you have a resource required by a web part, WSS has a defined way to store and access this resource. Custom web parts can be deployed to the wwwroot/bin directory or to the global assembly cache (GAC). The deployment location also affects the location of the resources directory. For GAC deployments, the directory is mapped to /_wpresources/[assembly_name]. For bin directory deployments, the directory is mapped to /wpresources/[assembly_name].

The workaround to this is to use the ClassResourcePath property. The SDK advises use to "Use the path returned by the ClassResourcePath property to prefix resource URLs for the browser to fetch."

The gotcha comes in when you try to access this external resource directly from disk when the context is a sub-site. Since the file is in a directory, I have always grabbed the file like this:

Dim resourceURI As URI = New Uri(ClassResourcePath)
Dim partResourcePath as String = Context.Server.MapPath(resourceURI.AbsolutePath)
.
.
.
Dim resourcePath as string = Path.Combine(partResourcePath, "somefile.xsl")
Dim trn As XslTransform = New XslTransform
trn.Load(resourcePath)

What is happening, however, is that the sub-site address is included in the ClassResourcePath. This is mapped correctly when requesting the file via the URL, but not whem mapping the path to a physical directory.

When using ClassResourcePath, be sure to use http to access the resource.

Thursday, January 27, 2005 4:16:30 PM (Central Standard Time, UTC-06:00)  #    Comments [0]  | 
Comments are closed.
Search

Further Reading...

Powered by: newtelligence dasBlog 2.2.8279.16125

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008, Paul Schaeflein

Send mail to the author(s) E-mail