473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to specify virtual paths in C#?

I'm trying to load an xslt file from my asp.net application directory and
I'm not sure what path to use. I thought no path would give me that path,
but it appears to give me the c:\windows\system32 path. Here's my code:

XslTransform xslTran = new XslTransform();
xslTran.Load("file.xslt");

I get an error saying it can't find the file:
"C:\Windows\System32\file.xslt"

I also have this problem when trying to write and xml file using the
dataset.WriteXml method. Not sure how to use virtual paths in C# code,
please help.

John
Nov 18 '05 #1
3 1300
You can use Server.MapPath(FileName) if your file is in the same folder as
the application.

Nikhil

"John Holmes" <jo****@co.skagit.wa.us> wrote in message
news:e6**************@TK2MSFTNGP10.phx.gbl...
I'm trying to load an xslt file from my asp.net application directory and
I'm not sure what path to use. I thought no path would give me that path,
but it appears to give me the c:\windows\system32 path. Here's my code:

XslTransform xslTran = new XslTransform();
xslTran.Load("file.xslt");

I get an error saying it can't find the file:
"C:\Windows\System32\file.xslt"

I also have this problem when trying to write and xml file using the
dataset.WriteXml method. Not sure how to use virtual paths in C# code,
please help.

John

Nov 18 '05 #2
Try this out
FileStream myFileStream = new FileStream(fileName,FileMode.Open,
FileAccess.Read);
StreamReader myXmlStream = new StreamReader(myFileStream);
xmlDoc.Load(myXmlStream);
myFileStream.Close();

Nikhil
"John Holmes" <jo****@co.skagit.wa.us> wrote in message
news:e6**************@TK2MSFTNGP10.phx.gbl...
I'm trying to load an xslt file from my asp.net application directory and
I'm not sure what path to use. I thought no path would give me that path,
but it appears to give me the c:\windows\system32 path. Here's my code:

XslTransform xslTran = new XslTransform();
xslTran.Load("file.xslt");

I get an error saying it can't find the file:
"C:\Windows\System32\file.xslt"

I also have this problem when trying to write and xml file using the
dataset.WriteXml method. Not sure how to use virtual paths in C# code,
please help.

John

Nov 18 '05 #3
Thanks for Nikhil's informative suggestions.

Hi John,

I think the "Server.MapPath" method Nikhil has mentioned is the one you
need. Here is the function's reference in MSDN:

#HttpServerUtility.MapPath Method
http://msdn.microsoft.com/library/en...webhttpserveru
tilityclassmappathtopic.asp?frame=true

#Server.MapPath
http://msdn.microsoft.com/library/en...rommp.asp?fram
e=true
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: jason | last post by:
I am getting twisted by the possibility that my virtual includes which currently work great on non-domain remote IP will crash if I purchase a domain and point it to one of my designated...
2
by: hawks5999 | last post by:
I have setup Software Update Service servers at two locations in our company (SUSserver1 and SUSserver2). I am modifying the web interface on one server so that it will allow me to control both...
13
by: Bryan Harrington | last post by:
Hello all.. I'm working on an application that I'd like to use some shared files. Right now my directory structure is: / (root) .../Shared/ .../Reports/ .../Tools/
0
by: Jason Moore | last post by:
I am trying to setup an asp.net web application without using a virtual directory, but when I do, the IDE forces me to use absolute paths so I cannot use root relative paths. Is there a way to...
1
by: Ian Turner | last post by:
Hi, Is there anyway, without dropping back to C++ and ISAPI filters, whereby I can route requests to virtual url paths through to the ASPNET runtime and ultimately processed by an HttpModule? ...
8
by: nick | last post by:
I have a problem and I've been using a cheezy work around and was wondering if anyone else out there has a better solution. The problem: Let's say I have a web application appA. Locally, I set...
3
by: Tom Hartland | last post by:
(Summary: is there a way to convert virtual paths to physical paths using PHP on IIS?) I hope I'm not covering old ground, but I've spent a couple of hours looking for this information and have...
3
by: Dhruba Bandopadhyay | last post by:
In classic ASP I could write: <!-- #INCLUDE VIRTUAL="Kevin\General\ServiceClass.asp" --> and it would "include" that ASP file into the current ASP file. My web application folder was not...
8
by: JJ | last post by:
I'm confused about paths. I have a functionn that uses the mappath method, which I think requires a virtual path (is that the same as a relative path?). But this doesn't always work as the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.