Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have a project in Visual Basic. I want to make it capable of being copied to a different computer, or stored on a USB. The issue is that the project writes files.

How do I get the program to find its own project directory, and then write to this file? E.g. for a vista it Goes C:\\Users\\... or for a USB it finds the string of the directory of usb so F:\\MyUSB\\...

Many thanks.
Posted
Updated 30-Apr-13 11:25am
v2
Comments
[no name] 30-Apr-13 15:55pm    
Try using GetExecutingAssembly()
Sergey Alexandrovich Kryukov 30-Apr-13 17:25pm    
Unfortunately, this is not quite correct and incomplete. What OP want needs to use GetEntryAssembly(). Nothing guarantees that the code is called from the code of the same assembly.
Please see my answer.
—SA

1 solution

I have the comprehensive answer. Pay attention for comparison with other methods — not all of them work correctly in all situations. Please see these answers:
How to find my programs directory (executable directory),
How to find my programs directory (current directory, "special folders").

—SA
 
Share this answer
 
Comments
Maciej Los 30-Apr-13 18:58pm    
Short and to the point, my 5!
Sergey Alexandrovich Kryukov 30-Apr-13 19:06pm    
Thank you, Maciej.
—SA
Aydin Homay 1-May-13 6:25am    
Really good ;) 5!
Sergey Alexandrovich Kryukov 1-May-13 10:27am    
Thank you, Aydin.
—SA

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