referencing from C: or D: drive
-
i wrote a little application that install a particular file in drive C. on installing the application on D drive,i had problem calling the file.how can i code for the file to be referenced irrespective of its installation path
ma coding life
The only idea I can think of involves creating a share folder where you write the file to. Then you could access the file via the share name. So it would be something like: \\computername\sharefoldername\file Of course the down side to this is you need to know the computer name, but that isn't real hard to figure out. Hope that helps. Ben
-
i wrote a little application that install a particular file in drive C. on installing the application on D drive,i had problem calling the file.how can i code for the file to be referenced irrespective of its installation path
ma coding life
If you install the file in the same folder, or below, as the exe then you can reference it from there. InstallDir: d:\MyApp File path: myfile.txt InstallDir: d:\MyApp\Files File path: /files/myfile.txt
only two letters away from being an asset
-
The only idea I can think of involves creating a share folder where you write the file to. Then you could access the file via the share name. So it would be something like: \\computername\sharefoldername\file Of course the down side to this is you need to know the computer name, but that isn't real hard to figure out. Hope that helps. Ben
:omg::wtf:
only two letters away from being an asset
-
:omg::wtf:
only two letters away from being an asset
I like your answer, but the way I understood the question was that you wouldn't know for sure which drive the file is on. (Of course, that is a little weird/ bad design) So if you don't know the drive letter you could acces it through a share. I suppose sometimes I think too much of answering the question instead of pushing for a better design. My fault. Ben
-
i wrote a little application that install a particular file in drive C. on installing the application on D drive,i had problem calling the file.how can i code for the file to be referenced irrespective of its installation path
ma coding life
How about looking at Application.StartupPath, or Path.GetDirectoryName(Assembly.GetExecutingAssembly.Location).
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
The only idea I can think of involves creating a share folder where you write the file to. Then you could access the file via the share name. So it would be something like: \\computername\sharefoldername\file Of course the down side to this is you need to know the computer name, but that isn't real hard to figure out. Hope that helps. Ben
-
If the file is on the same drive that the application is on, could you use Environment.CurrentDirectory to figure out which drive you are on. the use relative paths from there to get to your file. Hogan
That's a really bad idea. CurrentDirectory is NOT guaranteed to stay that way. Try opening any of the File/Folder dialogs and watch what happens to the current directory during the life of the dialog AND after the dialog. The current directory changes while the user navigates to pick files/folders. The current directory will not return to the original directory when the dialog was shown until after the dialog is dismissed AND the dialog object is told to reset the current directory to what it was when it was shown. Meanwhile, during the users navigation of the file system, the current directory always changes to match where the user is navigating. If you have a multithreaded app that mistakenly depends on current directory, you've got a huge problem!
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
That's a really bad idea. CurrentDirectory is NOT guaranteed to stay that way. Try opening any of the File/Folder dialogs and watch what happens to the current directory during the life of the dialog AND after the dialog. The current directory changes while the user navigates to pick files/folders. The current directory will not return to the original directory when the dialog was shown until after the dialog is dismissed AND the dialog object is told to reset the current directory to what it was when it was shown. Meanwhile, during the users navigation of the file system, the current directory always changes to match where the user is navigating. If you have a multithreaded app that mistakenly depends on current directory, you've got a huge problem!
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
i wrote a little application that install a particular file in drive C. on installing the application on D drive,i had problem calling the file.how can i code for the file to be referenced irrespective of its installation path
ma coding life
Hi, I am a bit surprised by the answers so far. For starters you cant hard code C: or D: or whatever. C: does not even have to exist; I have seen systems that boot and run from D: Second, you cant use CurrentDirectory, as Dave pointed out. You can not even use it if you store its startup value, since one may start an app with its CD preset to whatever value one chooses (try creating a desktop link, and watch its properties). third, wherever the app (the exe file) is located, you are not guaranteed that you can write to that folder. Unless your normal use is only reading that file, you should choose another place. The easy way out is by using the special folders, as can be found in the Environment.SpecialFolder enumeration; you will find some that are user-independent, others are user-specific. So I suggest reading up on that class. :)
Luc Pattyn [My Articles] [Forum Guidelines]