Server.MapPath in windows forms?

A

Alejandro Casal

Hi,

I'm developing a windows application and I want to load an XML schema into a
DataSet. In ASP.net I would use:

DS.ReadXMLSchema(Server.MapPath("file.xsd"));

But this doesn't seem to work in a windows app. Which is the counterpart
then of Server.MapPath in Windows Forms? Do I need any to use any extra
namespace?

Thanks,

Alejandro.
 
S

Scot Rose [MSFT]

In VB6 you would have used App.Path, In Dotnet the same capability maps to using

System.Reflection.Assembly.GetExecutingAssembly.Location

which returns the path of the assembly.

Look under "App Object Changes in Visual Basic .NET" for more information..

Scot Rose, MCSD
Microsoft Visual Basic Developer Support
Email : (e-mail address removed) <Remove word online. from address>

This posting is provided “AS IS”, with no warranties, and confers no rights.

Get Secure!
http://www.microsoft.com/security
http://www.microsoft.com/protect


--------------------
 
A

Alejandro Casal

Scot,

Sorry, I forgot to say I'm programming in C#. Have looked into what you said
but doesn't make much sense to me. Do you have other suggesitons?

Thanks again,

Alejandro.
 
K

Kellye Gaskill

Server.MapPath just appends the web directory to the filename.

You already know the filename, and Scot told you how to get the application
directory (assuming that is where the file is stored). You just need to
combine them.

string appDir = System.Reflection.Assembly.GetExecutingAssembly.Location;
DS.ReadXMLSchema(System.IO.Path.Combine(appDir, "file.xsd"));
 
D

Deepak Kapoor

You can use
System.Reflection.Assembly.GetExecutingAssembly.Location
in C# as well.

That's the beauty of the framework


Deepak

#*#*#*#*#*#*#*#*#*#*#*#*
I code therefore I am
 
A

Alejandro Casal

I had to add the '()' to GetExecutingAssembly since it is a method. Then
replaced the "\bin\app.exe" in appDir with "file.xsd" and it works.

Thanks,

Alejandro.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top