Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File path problem 1

Status
Not open for further replies.

lehuong

Programmer
Sep 2, 2003
98
US
Hi all,
I have created an application in VB .Net. When I run the application to open a file and generate a html file, it worked well. However, when I double click a file to open it and generate a html file, it shows an error could not find the mypicture.bmp. What I have in the generate file is:

Dim myImage As Image = Image.FromFile("mypicture.bmp")

I knew that when I double click on a file to open it, my application will change the directory to that file's directory which does not contain mypicture.bmp file (mypicture.bmp is in bin folder). Is there anyway to fix this kind of problem?
lehuong
 
I'm not sure that I will get this right because I'm not entirely sure that I understand your questions, but I'll try anyway. I'm assuming that "mypicture.bmp" is in the same folder as your application assembly. If this is the case then the following code should solve your problem.

Code:
Dim imageFileName as String = System.IO.Path.Combine( _
    System.AppDomain.CurrentDomain.BaseDirectory(), _
    "mypicture.bmp")
Dim myImage As Image = Image.FromFile(imageFileName)

The System.AppDomain.CurrentDomain.BaseDirectory() function returns the folder from which your current application was launched. There are a couple of other ways to get this information, but this is the only way to retrieve this information no matter what type of .Net project you are developing.
 
Thanks Stravis,
It works well now, thank you for your help.

lehuong
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top