1

I made a complete C# WinForm project. When I was working I gave my flash files a whole address and called them like:

flashForm.MOVIE = @"D:\poem.swf";

But when I wanted to build my project as I wanted them to be in same folder as my exe setup is I removed the address and wrote code like below to find the flash file beside it like below:

flashForm.MOVIE = "poem.swf";

I think there is a mistake. How can I give the address of user setup to this line of code? Thanks for helping.

HasaniH
  • 8,232
  • 6
  • 41
  • 59
  • What kind of application you are targetting ? WinForm, WPF, ASP.Net ? – Habib Oct 29 '13 at 14:47
  • thats a winform project –  Oct 29 '13 at 14:48
  • See: http://stackoverflow.com/questions/295687/get-path-to-execution-directory-of-windows-forms-application – Habib Oct 29 '13 at 14:50
  • either use working directory of your app or if you want the user to choose this path during installation then add a registry key – makc Oct 29 '13 at 14:52

1 Answers1

2
string directory = AppDomain.CurrentDomain.BaseDirectory;

This will give you the directory of your application. You can then use Path.Combine(directory, fileName) to get your files. In your example:

string movieName = "poem.swf";
string pathToMovie = Path.Combine(directory, movieName);

As I said: this is only correct if you store the file poem.swf in the same directory as your application.

If you don't store your files with your application, you need to find another way to find them. As makc wrote in his comment, you can do this via the registry or let the user chose where to look.

germi
  • 4,628
  • 1
  • 21
  • 38
  • so you think i have write that line of code like:?flashForm.MOVIE = AppDomain.CurrentDomain.BaseDirectory+@"\poem.swf"; –  Oct 29 '13 at 14:51
  • Depending on where exactly you store your files. If it's somewhere with your application, this will give you the starting directory. I updated my answer with an example. – germi Oct 29 '13 at 14:52