im junir for vb 2010, im tring to make small program, which when select picture in opendialog,( give path of image into text box(txtGrupAddNewArtWrokUploadImage.Text) ) copy to folder(ArtWork) which in application installed folder. i try to filecopy command using give target path like"c:\temp\image.jpg" command is working but when i chenge command like;

FileCopy(txtGrupAddNewArtWrokUploadImage.Text, System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("ReNewArtWorkProgect.exe", "ArtWork\") +OpenFileDialogPicture.SafeFileName)

give error,
DirectoryNotFoundExeption Was Unhandled ,( Could not find a part of the path "c:\Program file\ArtWork\Image.jpg")
please can u help me kindly,
Tks,
Achi

Does the ArtWork folder exist at that location?

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?

Yes, the ArtWork folder exist at that location ("...bin\debug\Artwork") ;
And

"FileCopy(txtGrupAddNewArtWrokUploadImage.Text, Application.StartupPath + "\Artwork")"

is not working, it make only file which named "artwork" in debug folder.

And ArtWork folder I alredy created in debug folder.

And also,
"+OpenFileDialogPicture.SafeFileName"
I use this for when cording "filecopy" it have to give target location and file name, i use it for get file name.

and,

i cording in like this it working well,

FileCopy(txtGrupAddNewArtWrokUploadImage.Text, "G:\Documents and Settings\Achi\Desktop\Image.jpg")

i don't no why Application.StartupPath is not working..
i'm suffer this matter when last 3 month. please help to me finish my programe....

Yes, the ArtWork folder exist at that location ("...bin\debug\Artwork") ;

That's not the location referenced by your error.

Sorry, I was a little rushed when I gave you that.

Try this,

FileCopy(txtGrupAddNewArtWrokUploadImage.Text, Application.StartupPath + "\Artwork\" + OpenFileDialogPicture.SafeFileName)

it also given befor error again, (could not find path)

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.

if it has some another way for copy file please letme know....

'imports

    Imports System.Data.OleDb
    Imports System.IO

     'Database 



    Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\newartwork.accdb; Jet OLEDB:Database Password=98644528 ")

     'Menu Add New Artwork 


         Private Sub NewArtWorkToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewArtWorkToolStripMenuItem.Click
                Call Loading()
                Dim NewArt As New OleDbDataAdapter("SELECT Reff_table.Reff FROM Reff_table ORDER BY Reff_table.Reff", con)
                Dim DSNewArt As New DataSet

                grupAddNewArtWork.Show()
                NewArt.Fill(DSNewArt, "Ref")
                comboGrupAddNewArtWrokEterReff.DataSource = DSNewArt.Tables("ref")
                comboGrupAddNewArtWrokEterReff.DisplayMember = "reff"
                comboGrupAddNewArtWrokEterReff.Text = ""

            End Sub

    'Button UploadFile 

      Private Sub buttGrupAddNewArtWorkUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttGrupAddNewArtWorkUpload.Click
            OpenFileDialogPicture.InitialDirectory = System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("ReNewArtWorkProgect.exe", "ArtWork\\")
            OpenFileDialogPicture.RestoreDirectory = True

            If OpenFileDialogPicture.ShowDialog() = Windows.Forms.DialogResult.OK Then
                txtGrupAddNewArtWrokUploadImage.Text = OpenFileDialogPicture.FileName
            End If

            If txtGrupAddNewArtWrokUploadImage.Text <> "" Then
                PictureBoxGupAddNewArtWork.ImageLocation = txtGrupAddNewArtWrokUploadImage.Text
            Else
                PictureBoxGupAddNewArtWork.ImageLocation = ""
            End If

        End Sub

    'Save Button 



        Private Sub buttGrupAddNewArtWorkSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttGrupAddNewArtWorkSave.Click
                Dim NewArt_1 As New OleDbDataAdapter("SELECT COUNT(*) FROM Reff_table WHERE Reff_table.reff='" & comboGrupAddNewArtWrokEterReff.Text & "' ", con)
                Dim DSNewArt_1 As New DataSet
                Dim contRef As Integer




                Dim PIC As String
                Dim FILE As String

                FILE = OpenFileDialogPicture.SafeFileName

                'PIC = System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("ReNewArtWorkProgect.exe", "ArtWork\")


                PIC = Application.StartupPath + "\Artwork\" + OpenFileDialogPicture.SafeFileName

                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
                    MsgBox("Please Select Art Work Image # ...!")
                    OpenFileDialogPicture.ShowDialog()
                    txtGrupAddNewArtWrokUploadImage.Text = OpenFileDialogPicture.FileName
                    PictureBoxGupAddNewArtWork.ImageLocation = txtGrupAddNewArtWrokUploadImage.Text
                Else



                    If FILE.Exists(txtGrupAddNewArtWrokUploadImage.Text) Then
                        FileCopy(txtGrupAddNewArtWrokUploadImage.Text, Application.StartupPath + "\Artwork\" + OpenFileDialogPicture.SafeFileName)
                    End If


                    'FileCopy(txtGrupAddNewArtWrokUploadImage.Text, Application.StartupPath + "\Artwork\" + OpenFileDialogPicture.SafeFileName)
                    'FileCopy(txtGrupAddNewArtWrokUploadImage.Text, "G:\Documents and Settings\Achi\Desktop" + FILE)
                    'System.IO.File.Copy(txtGrupAddNewArtWrokUploadImage.Text, "G:\Documents and Settings\Achi\Desktop" + FILE)


                    SaveNewArtWork.CommandText = (" INSERT INTO Reff_table (Reff,Artwork,pictur) VALUES ('" & comboGrupAddNewArtWrokEterReff.Text & "','" & txtGrupAddNewArtWrokEnterArtWork.Text & "', '" & PIC & "' )")
                    SaveNewArtWork.ExecuteNonQuery()
                    MsgBox("New Ref # '" & comboGrupAddNewArtWrokEterReff.Text & "'  Is Save Success ...!")



                End If

                con.Close()

            End Sub

this is my code, if it has some error or wrong coding please let me know...

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

i copied all ur code , but it gived befor error again, i could find what is it...

 FileCopy(txtGrupAddNewArtWrokUploadImage.Text, Application.StartupPath + "\Artwork\" + FILEName)
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)

Sorry for change code,

If FILE.Exists(txtGrupAddNewArtWrokUploadImage.Text) Then

End If

i tried ur code as you send, it not work, becouse "file.exist" is give error becouse "file" also make string variable then give error "exists is not string" then i change variable FILE as FILEName then that error not visible. is it affect to program ???... and also i tried using below code it also not working. Please if it has some another way to copy file, please let me know.

File.Copy(txtGrupAddNewArtWrokUploadImage.Text, Application.StartupPath + "\Artwork\" + FILEName)

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

Same problem agin, i cant image is my code worng another place.

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.

again give error. (i dit put ur Msgbox comand also it give correct path which image have to save and correct file name.) it give error, "could not find path" it show correct path wich path of image have to save path and file name. when i chang path to "G:\Documents and Settings\Achi\Desktop\" + NEWFILE" image was copied. i'm so confuse to find where problem is,

Does the image load into the picturebox?

yes it show picture well.

Thanks tinstaafi, thanks....
i solved error , it happen to Name of folder which ArtWork, that folder i was create like "Art Work" we give code like "ArtWork" it's my mistake, im beging sorry for if u had trable from me,
And i want to know another two problem,
1. how to make unstall program when click some button in my aplication
2. how to delete data base after 5 day's when click some button (maybe application close)
if u can help me it very important to me.

how to make unstall program when click some button in my aplication

Try using the Setup and Deploy project. I'm not that familiar with it, but researching the documentation should be able to help.

how to delete data base after 5 day's when click some button (maybe application close)

Sorry I'm not that familiar with databases, but you should be able to run a query for any records that are more than 5 days old and then send a command to delete them.

thanks...........

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.