Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey everyone.

I have question to get your ideas.

I wrote a code that operates a file, let's say "filex". There is no problem in my computer while working, but when I install my program into an another computer, I have to change the path of filex to work properly.

I'm making simple file operations on filex, nothing more.

What can I do to overcome this? What is your ideas?

My best Regards...
Posted

It is better to get your file paths from an external source ie configuration file, so you can change that at runtime without needing a recompile.

You can also reference your files via getting your applications directory Directory.GetCurrentDirectory() and building your paths in the the applications folder.

app.exe
|-Output 
    |- filex
 
Share this answer
 
Comments
Un_NaMeD 20-Sep-11 4:24am    
Hey Mehdi,
I guess You misunderstood me, What I understand from your saying is I need a configuration file, but aren't that will be specific for all other computers? I need something solid for all users.
And could you please explain more the Directory.GetCurrentDirectory() method?
Thanks...
Mehdi Gholam 20-Sep-11 4:30am    
http://msdn.microsoft.com/en-us/library/system.io.directory.getcurrentdirectory.aspx
Un_NaMeD 22-Sep-11 10:54am    
Hey Mehdi,
That helped, but there is another problem now.
When I tried to read the file from the location I give, it does'nt read the file truely. I mean it reads something which is not read in the file.
Do you have any idea how can this be?
Thank you.
My regards...
Un_NaMeD 22-Sep-11 10:58am    
here is the code to location I adjust myself...

string path = Directory.GetCurrentDirectory();
path = path + "\\hucre.txt";

hucre.txt is the file I'm trying to read...
Hi
If you are reluctant to use config file, you can use the directory of executable file location

C#
var binFolder = new DirectoryInfo(Application.ExecutablePath).Parent;


Hope this helps you...
 
Share this answer
 
save path of file in config file . done coding according to that. when u install program on another machine just chane the path from config file according to machine.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900