Maya Shb
Maya Shb

Reputation: 1

import image to picture box from desktop user

I want to import a picture from folder which created by project when installed on user desktop but each user have different user name , how can i import from picture from dsektop user

Here is My code

 Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) _
                Handles Button2.Click
      PictureBox1.Image = Image.FromFile("(My.Computer.FileSystem.SpecialDirectories.Desktop, "New folder") \" + ID.Text + ".png")
 end sub 

Upvotes: 0

Views: 4490

Answers (1)

Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

this will resolve to the desktop folder for the current user. Are you really creating folders on the desktop? Usually data and subfolders are stored in AppData.

EDIT

I SUSPECT you might have need of this folder in other places and even if not it can be saved and 'fixed' before hand. Elsewhere, like when the app starts:

Friend mUserFolder As String
mUserFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
' your code was not adding the required backslash
mUserFolder &= "\Data\"           ' append the sub folder name

Now to load the file in button click the code is simpler to read and debug:

 PictureBox1.Image = Image.FromFile(muserFolder & ID.Text & ".png")

Also use & for concatenating strings instead of +

Upvotes: 2

Related Questions