Problem with System.Drawing.Bitmap()

A

Anthony P.

Hello Everyone,

In my form_load() method, I have the following code:

sPath = System.IO.Path.GetDirectoryName( _
System.Reflection.Assembly.GetExecutingAssembly().GetName
().CodeBase())

PictureBox1.Image = New System.Drawing.Bitmap(sPath & "\data\pic-
logo.gif")

Pretty simple code that is supposed to load the pic-logo.gif stored in
the Application's directory\data into a picture box on the form.

So, let's say my sPath is set to C:\MyDirectory. So, the pic should be
pulled from C:\MyDirectory\data\pic-logo.gif, right? Nope!

For some reason, the system is placing \ in front of the path name.
So, my call is actually coming out as \C:\MyDirectory\Data\pic-
logo.gif.

I've even tried hard coding the path into the call and it STILL is
putting a \ in front of the path.

Any idea what might be going on here?

Thank You!
Anthony
 
O

Onur Güzel

Hello Everyone,

In my form_load() method, I have the following code:

sPath = System.IO.Path.GetDirectoryName( _
            System.Reflection.Assembly.GetExecutingAssembly()..GetName
().CodeBase())

PictureBox1.Image = New System.Drawing.Bitmap(sPath & "\data\pic-
logo.gif")

Pretty simple code that is supposed to load the pic-logo.gif stored in
the Application's directory\data into a picture box on the form.

So, let's say my sPath is set to C:\MyDirectory. So, the pic should be
pulled from C:\MyDirectory\data\pic-logo.gif, right? Nope!

For some reason, the system is placing \ in front of the path name.
So, my call is actually coming out as \C:\MyDirectory\Data\pic-
logo.gif.

I've even tried hard coding the path into the call and it STILL is
putting a \ in front of the path.

Any idea what might be going on here?

Thank You!
Anthony

Hi,

Try using "Application.StartupPath" and combine it with your trailing
path.

Like:

' If i remember correct...
Dim sPath As String
sPath = Applicaton.StartupPath & "\data\pic-logo.gif"

Application.StartupPath will locate the path wherever your applicaton
resides on.

Hope it solves,

Onur Guzel
 
A

Anthony Papillion

Application.StartupPath will locate the path wherever your applicaton
resides on.

Hope it solves,

Onur Guzel- Hide quoted text -

Hi Onur,

Thanks for the response. Unfortunately, that didn't solve it. It's
kind of odd because the code I showed above actually pointed to the
right place. The problem was that the system was adding a back slash
to the path before the pathname. So let's say my path was C:\Program
Files\MyProgram\Data\logo.gif, the system was reading it as \C:
\Program Files\MyProgram\Data\logo.gif. It was almost like it was
expecting a UNC.

Ultimately, I simply removed the code and hard coded a location.
Obviously, that won't work for deployment though so I do need to solve
this. It's REALLY got me baffled!

Anthony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top