0

Greetings to all,

I want to use the "System.IO.File.Delete(PATH);" function to delete a file that is in my Project whenever I run the app.

The problem is that in order for this to work I have to specify a full path
"C:\Users\SomeUser\Desktop\SomeAppFolder\Content\Models\Model1.X"

The problem is that this path is different from one computer to another, so this will only work on my computer.

Is there a way to specify a Default Path that would make this method work on any computer?

Thanks in advance.

Edited by 0xCMD: n/a

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Geekitygeek
1

Should be able to use this to do what you want...

string path;
   path = System.IO.Path.GetDirectoryName( 
      System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );

Got that from this source. There's also a VB method there as well.

Hope this helps :) Please mark as solved once your issue is resolved.

Votes + Comments
Thanks I'll try the suggestion and reply back.
2

Or similarly string path = System.Reflection.Assembly.GetExecutingAssembly().Location returns the path of the file containing the exectable :)

Edited by Geekitygeek: lost code tags

Votes + Comments
Thanks.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.