Server.MapPath in windows forms?

  • Thread starter Thread starter Alejandro Casal
  • Start date Start date
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.
 
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


--------------------
 
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.
 
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"));
 
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
 
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.
 
Back
Top