Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 29th, 2003, 11:32 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default Pathing

Hello,

I'm still getting used to virtual directories in web development. I have IIS set up my web server on the folder c:\inetpub\wwwroot. I have the following folder structure:

/WebApplication1 - Project folder (virtual directory)
  /classes - VB.NET class files
  /documents
    /schemas - XML schemas
    /stylesheets - XSL stylesheets
    /xml - XML files

In the root, I have ASP.NET pages. Now, all of this is in the WebApplication1 folder. Now, I have a class file SiteLayout.vb which makes a reference to an XML and Stylesheet file in the appropriate folders above. The code is specified as:
Code:
dim objXSLT as new XslTransform
objXSLT.Load(Server.MapPath("/documents/stylesheets/styles.xslt"))
I get an error saying it can't find the file in: c:\inetpub\wwwroot\documents\stylesheets\styles.xs lt

which is occuring because it can't find the virtual directory folder. How do I account for this? I don't want to hard code the value of the virtual directory folder because it will change as I move to different environments.

Thanks,

Brian Mains
__________________
Brian
 
Old December 29th, 2003, 03:54 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

.net lets you use the ~ as a placeholder for the current application directory.

objXSLT.Load(Server.MapPath("~/documents/stylesheets/styles.xslt"))

.net will replace ~ with the application root if there is one.

Keep in mind that even though your .vb file lives under a subdirectory in the application, its code is compiled and lives in the DLL that is in /bin of the application. Of course, this is irrelevant still because the code is EXECUTING at the level of the AS?X. If the page is at the root, you could use this successfully:

objXSLT.Load(Server.MapPath("documents/stylesheets/styles.xslt"))

Only if the AS?X is running under a sub directory do you need to worry about "backing up" to get at files in other directories. To be on the safe side, I always use "~/..." and reference everything from the root of my application.

Peter
------------------------------------------------------
Work smarter, not harder.









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.