开发者

Reference XSLT-file using a project relative way (instead of an absolute path)

开发者 https://www.devze.com 2022-12-22 22:42 出处:网络
The file at xsltFileName is in my project WebSite2 (at the root-level of the project). I currently use an absolute path to get the XSLT file name:

The file at xsltFileName is in my project WebSite2 (at the root-level of the project). I currently use an absolute path to get the XSLT file name:

XslCompiledTransform xslt = new XslCompiledTransform();
String xsltFileName = "file:///C:\\Documents and Settings\\kentl\\My Documents\\Visual Studio 2005\\WebSites\\WebSite2\\page.xsl";
xslt.Load(xsltFileName);

I would like to have a so开发者_JAVA技巧lution without an absolute path. What would be the cleanest way?


XslCompiledTransform xslt = new XslCompiledTransform();
String xsltFileName = Server.MapPath("~/page.xsl");
xslt.Load(xsltFileName);

Or, if you are not inside a Web Form (i.e., a Business Object):

XslCompiledTransform xslt = new XslCompiledTransform();
String xsltFileName = System.Web.HttpContext.Current.Server.MapPath("~/page.xsl");
xslt.Load(xsltFileName);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号