Does the ArtWork folder exist at that location?
deceptikon
Challenge Accepted
3,499 posts since Jan 2012
Reputation Points: 822
Solved Threads: 481
Skill Endorsements: 58
If I understand what you're trying to do, this might work:
FileCopy(txtGrupAddNewArtWrokUploadImage.Text, Application.StartupPath + "\Artwork")
This assumes that Artwork is in the folder where your program resides and that it is already created.
+OpenFileDialogPicture.SafeFileName
Not sure why you have this in there. Are you trying to copy the file to a subfolder of Artwork?
tinstaafl
Nearly a Posting Virtuoso
1,472 posts since Jun 2010
Reputation Points: 429
Solved Threads: 262
Skill Endorsements: 14
Yes, the ArtWork folder exist at that location ("...bin\debug\Artwork") ;
That's not the location referenced by your error.
deceptikon
Challenge Accepted
3,499 posts since Jan 2012
Reputation Points: 822
Solved Threads: 481
Skill Endorsements: 58
Sorry, I was a little rushed when I gave you that.
Try this,
FileCopy(txtGrupAddNewArtWrokUploadImage.Text, Application.StartupPath + "\Artwork\" + OpenFileDialogPicture.SafeFileName)
tinstaafl
Nearly a Posting Virtuoso
1,472 posts since Jun 2010
Reputation Points: 429
Solved Threads: 262
Skill Endorsements: 14
Artwork has to be created first in order for it to work. If you need to create it in run time, make sure you Imports System.IO first, then use the Directory class.
If Not Directory.Exists(Application.StartupPath + "\Artwork") Then
Directory.CreateDirectory(Application.StartupPath + "\Artwork")
End If
Plus you should check to make sure the source file exists before you try to copy it, again make sure System.IO is imported.
If File.Exists(txtGrupAddNewArtWrokUploadImage.Text) Then
FileCopy(txtGrupAddNewArtWrokUploadImage.Text, Application.StartupPath + "\Artwork\" + OpenFileDialogPicture.SafeFileName)
End If
I've tested the code I gave you and I know it works, basically as the programmer you have to makes sure the parts are in place in order for the code to work. If you still have a problem, I'd like to see the code you use to put the file path into the textbox.
tinstaafl
Nearly a Posting Virtuoso
1,472 posts since Jun 2010
Reputation Points: 429
Solved Threads: 262
Skill Endorsements: 14
Only a couple of things jumped out at me, that could be changed. I copied Lines 61 & 66 and added them to after you show the OpenFileDialog, again. I showed you how to use the Title of the OpenFileDialog to send a message to the user. This eliminates the need for another messagebox. I added a check for pressing the Cancel button, and exiting the routine if it is pressed. I changed the statmenmt OpenFileDialogPicture.SafeFileName to FILE. This way if you need to make a change to FILE the change will be reflected throughout your instead of having to find every instance of OpenFileDialogPicture.SafeFileName and changing that. Hope this works for you.
Dim PIC As String = ""
Dim FILE As String = ""
FILE = OpenFileDialogPicture.SafeFileName
PIC = Application.StartupPath + "\Artwork\" + FILE
MsgBox(PIC)
con.Open()
Dim SaveNewArtWork As New OleDbCommand
SaveNewArtWork.Connection = con
NewArt_1.Fill(DSNewArt_1, "COUntref")
contRef = DSNewArt_1.Tables("COUntref").Rows(0).Item(0)
If comboGrupAddNewArtWrokEterReff.Text = "" Then
MsgBox("Please Enter New Reference No# ...!")
comboGrupAddNewArtWrokEterReff.Focus()
ElseIf contRef > 0 Then
MsgBox("Ref # '" & comboGrupAddNewArtWrokEterReff.Text & "' Is Alredy Enterd; Please Enter New Reference No# ...!")
comboGrupAddNewArtWrokEterReff.Text = ""
comboGrupAddNewArtWrokEterReff.Focus()
ElseIf txtGrupAddNewArtWrokEnterArtWork.Text = "" Then
MsgBox("Please Enter Art Work ...!")
txtGrupAddNewArtWrokEnterArtWork.Focus()
ElseIf txtGrupAddNewArtWrokUploadImage.Text = "" Then
OpenFileDialogPicture.Title = "Please Select Art Work Image # ...!"
'If the user presses the OK button then continue else the user pressed the Cancel button then exit the routine, or whatever you want
If OpenFileDialogPicture.ShowDialog() = Windows.Forms.DialogResult.OK Then
txtGrupAddNewArtWrokUploadImage.Text = OpenFileDialogPicture.FileName
PictureBoxGupAddNewArtWork.ImageLocation = txtGrupAddNewArtWrokUploadImage.Text
'I copied these down here to get the current values from the OpenFileDialog
FILE = OpenFileDialogPicture.SafeFileName
PIC = Application.StartupPath + "\Artwork\" + FILE
MsgBox(PIC)
Else
Return
End If
Else
If FILE.Exists(txtGrupAddNewArtWrokUploadImage.Text) Then
FileCopy(txtGrupAddNewArtWrokUploadImage.Text, Application.StartupPath + "\Artwork\" + FILE)
End If
tinstaafl
Nearly a Posting Virtuoso
1,472 posts since Jun 2010
Reputation Points: 429
Solved Threads: 262
Skill Endorsements: 14
FileCopy(txtGrupAddNewArtWrokUploadImage.Text, Application.StartupPath + "\Artwork\" + FILEName)
That is not a copy of my code. My code says,
FileCopy(txtGrupAddNewArtWrokUploadImage.Text, Application.StartupPath + "\Artwork\" + FILE)
tinstaafl
Nearly a Posting Virtuoso
1,472 posts since Jun 2010
Reputation Points: 429
Solved Threads: 262
Skill Endorsements: 14
Here try this. I missed the variable FILE before. You can't use variable names that are keywords. I changed FILE to NEWFILE it should work for you now.
Dim PIC As String = ""
Dim NEWFILE As String = ""
NEWFILE = OpenFileDialogPicture.SafeFileName
PIC = Application.StartupPath + "\Artwork\" + NEWFILE
MsgBox(PIC)
con.Open()
Dim SaveNewArtWork As New OleDbCommand
SaveNewArtWork.Connection = con
NewArt_1.Fill(DSNewArt_1, "COUntref")
contRef = DSNewArt_1.Tables("COUntref").Rows(0).Item(0)
If comboGrupAddNewArtWrokEterReff.Text = "" Then
MsgBox("Please Enter New Reference No# ...!")
comboGrupAddNewArtWrokEterReff.Focus()
ElseIf contRef > 0 Then
MsgBox("Ref # '" & comboGrupAddNewArtWrokEterReff.Text & "' Is Alredy Enterd; Please Enter New Reference No# ...!")
comboGrupAddNewArtWrokEterReff.Text = ""
comboGrupAddNewArtWrokEterReff.Focus()
ElseIf txtGrupAddNewArtWrokEnterArtWork.Text = "" Then
MsgBox("Please Enter Art Work ...!")
txtGrupAddNewArtWrokEnterArtWork.Focus()
ElseIf txtGrupAddNewArtWrokUploadImage.Text = "" Then
OpenFileDialogPicture.Title = "Please Select Art Work Image # ...!"
'If the user presses the OK button then continue else the user pressed the Cancel button then exit the routine, or whatever you want
If OpenFileDialogPicture.ShowDialog() = Windows.Forms.DialogResult.OK Then
txtGrupAddNewArtWrokUploadImage.Text = OpenFileDialogPicture.FileName
PictureBoxGupAddNewArtWork.ImageLocation = txtGrupAddNewArtWrokUploadImage.Text
NEWFILE = OpenFileDialogPicture.SafeFileName
PIC = Application.StartupPath + "\Artwork\" + NEWFILE
MsgBox(PIC)
Else
Return
End If
Else
If File.Exists(txtGrupAddNewArtWrokUploadImage.Text) Then
FileCopy(txtGrupAddNewArtWrokUploadImage.Text, Application.StartupPath + "\Artwork\" + NEWFILE)
End If
tinstaafl
Nearly a Posting Virtuoso
1,472 posts since Jun 2010
Reputation Points: 429
Solved Threads: 262
Skill Endorsements: 14
I'm thinking that because there's no check to see if an image was uploaded, NEWFILE could be "". I've added a check in there, see if that works. The base code for copying the file works, it's just a matter of making sure all the parts are valid. If you still get an error in the filecopy statement comment it out and put in MsgBox("txtGrupAddNewArtWrokUploadImage.Text - "+ txtGrupAddNewArtWrokUploadImage.Text + vbNewLine + "Application.StartupPath + "\Artwork\" + NEWFILE - " + Application.StartupPath + "\Artwork\" + NEWFILE), and see what values are being passed. This will give you a better idea of where the problem is.
Dim PIC As String = ""
Dim NEWFILE As String = ""
NEWFILE = OpenFileDialogPicture.SafeFileName
If NEWFILE <> "" Then
PIC = Application.StartupPath + "\Artwork\" + NEWFILE
MsgBox(PIC)
con.Open()
Dim SaveNewArtWork As New OleDbCommand
SaveNewArtWork.Connection = con
NewArt_1.Fill(DSNewArt_1, "COUntref")
contRef = DSNewArt_1.Tables("COUntref").Rows(0).Item(0)
If comboGrupAddNewArtWrokEterReff.Text = "" Then
MsgBox("Please Enter New Reference No# ...!")
comboGrupAddNewArtWrokEterReff.Focus()
ElseIf contRef > 0 Then
MsgBox("Ref # '" & comboGrupAddNewArtWrokEterReff.Text & "' Is Alredy Enterd; Please Enter New Reference No# ...!")
comboGrupAddNewArtWrokEterReff.Text = ""
comboGrupAddNewArtWrokEterReff.Focus()
ElseIf txtGrupAddNewArtWrokEnterArtWork.Text = "" Then
MsgBox("Please Enter Art Work ...!")
txtGrupAddNewArtWrokEnterArtWork.Focus()
ElseIf txtGrupAddNewArtWrokUploadImage.Text = "" Then
OpenFileDialogPicture.Title = "Please Select Art Work Image # ...!"
'If the user presses the OK button then continue else the user pressed the Cancel button then exit the routine, or whatever you want
If OpenFileDialogPicture.ShowDialog() = Windows.Forms.DialogResult.OK Then
txtGrupAddNewArtWrokUploadImage.Text = OpenFileDialogPicture.FileName
PictureBoxGupAddNewArtWork.ImageLocation = txtGrupAddNewArtWrokUploadImage.Text
NEWFILE = OpenFileDialogPicture.SafeFileName
PIC = Application.StartupPath + "\Artwork\" + NEWFILE
MsgBox(PIC)
Else
Return
End If
Else
If File.Exists(txtGrupAddNewArtWrokUploadImage.Text) Then
FileCopy(txtGrupAddNewArtWrokUploadImage.Text, Application.StartupPath + "\Artwork\" + NEWFILE)
End If
End If
Else
MsgBox("Upload an image first")
Return
End If
Alternatively, you could start with buttGrupAddNewArtWorkSave disabled, then enable it in buttGrupAddNewArtWorkUpload, then disable it again whenever buttGrupAddNewArtWorkSave exits.
tinstaafl
Nearly a Posting Virtuoso
1,472 posts since Jun 2010
Reputation Points: 429
Solved Threads: 262
Skill Endorsements: 14
Does the image load into the picturebox?
tinstaafl
Nearly a Posting Virtuoso
1,472 posts since Jun 2010
Reputation Points: 429
Solved Threads: 262
Skill Endorsements: 14