Skip to main content
added 421 characters in body; added 92 characters in body; added 4 characters in body
Source Link

My code behind code from the aspx webpage uses a transform.xsl to do some custom xslt transformation.

Scenario 1: Try to get the file from the _layouts folder.

SPWeb web = SPContext.Current.Web;
SPFile file = web.GetFile(@"/layouts/MyFeature/transform.xsl");

Note : The file is accesible on this url http://mysite:8080/_layouts/MyFeature/transform.xsl when using the browser.

Scenario 2: Try to get the file from the current (http://mysite:8080/MyFeature/MyPage.aspx) url.

SPWeb web = SPContext.Current.Web;
SPFile file = web.GetFile(@"transform.xsl");

or

SPFile file = web.GetFile(@"MyFeature/transform.xsl");

or

SPFile file = web.GetFile(@"/MyFeature/transform.xsl");

All scenarios fail, how to solve this?

Solution
The 'transform.xsl' is now located at 'MyFeature/transform.xsl' and I've followed the tip from Anders Rask, and my code looks like this now:

SPWeb web = SPContext.Current.Web;
XslCompiledTransform transformer = new XslCompiledTransform();

XsltSettings settings = new XsltSettings(true, true);
string xslLocation = web.Url + "/FormWrapper/transform.xsl";
transformer.Load(xslLocation, settings, GetResolverWithDefaultCredentials());

// Do XSLT transform...

My code behind code from the aspx webpage uses a transform.xsl to do some custom xslt transformation.

Scenario 1: Try to get the file from the _layouts folder.

SPWeb web = SPContext.Current.Web;
SPFile file = web.GetFile(@"/layouts/MyFeature/transform.xsl");

Note : The file is accesible on this url http://mysite:8080/_layouts/MyFeature/transform.xsl when using the browser.

Scenario 2: Try to get the file from the current (http://mysite:8080/MyFeature/MyPage.aspx) url.

SPWeb web = SPContext.Current.Web;
SPFile file = web.GetFile(@"transform.xsl");

or

SPFile file = web.GetFile(@"MyFeature/transform.xsl");

or

SPFile file = web.GetFile(@"/MyFeature/transform.xsl");

All scenarios fail, how to solve this?

My code behind code from the aspx webpage uses a transform.xsl to do some custom xslt transformation.

Scenario 1: Try to get the file from the _layouts folder.

SPWeb web = SPContext.Current.Web;
SPFile file = web.GetFile(@"/layouts/MyFeature/transform.xsl");

Note : The file is accesible on this url http://mysite:8080/_layouts/MyFeature/transform.xsl when using the browser.

Scenario 2: Try to get the file from the current (http://mysite:8080/MyFeature/MyPage.aspx) url.

SPWeb web = SPContext.Current.Web;
SPFile file = web.GetFile(@"transform.xsl");

or

SPFile file = web.GetFile(@"MyFeature/transform.xsl");

or

SPFile file = web.GetFile(@"/MyFeature/transform.xsl");

All scenarios fail, how to solve this?

Solution
The 'transform.xsl' is now located at 'MyFeature/transform.xsl' and I've followed the tip from Anders Rask, and my code looks like this now:

SPWeb web = SPContext.Current.Web;
XslCompiledTransform transformer = new XslCompiledTransform();

XsltSettings settings = new XsltSettings(true, true);
string xslLocation = web.Url + "/FormWrapper/transform.xsl";
transformer.Load(xslLocation, settings, GetResolverWithDefaultCredentials());

// Do XSLT transform...
Source Link

How to access a file in the current url or _layouts folder ?

My code behind code from the aspx webpage uses a transform.xsl to do some custom xslt transformation.

Scenario 1: Try to get the file from the _layouts folder.

SPWeb web = SPContext.Current.Web;
SPFile file = web.GetFile(@"/layouts/MyFeature/transform.xsl");

Note : The file is accesible on this url http://mysite:8080/_layouts/MyFeature/transform.xsl when using the browser.

Scenario 2: Try to get the file from the current (http://mysite:8080/MyFeature/MyPage.aspx) url.

SPWeb web = SPContext.Current.Web;
SPFile file = web.GetFile(@"transform.xsl");

or

SPFile file = web.GetFile(@"MyFeature/transform.xsl");

or

SPFile file = web.GetFile(@"/MyFeature/transform.xsl");

All scenarios fail, how to solve this?