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.

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.

commented: Thanks I'll try the suggestion and reply back. +0

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

commented: Thanks. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.