I am using the below code to copy a file to a network location and store the file information in an access database.
Dim SqlString1 As String = "INSERT INTO document (incidentid, documentno, documentname, documentpath) VALUES (@incid, @docid, @FileName, @FilePath)"
Using conn As New OleDbConnection(ConnString)
conn.Open()
If Me.TextBox1.Text <> "" Then
'THIS WILL SAVE THE FILE TO A LOCATION
Dim fileLocation As String = OpenFileDialog1.FileName
File.Copy(fileLocation, Path.Combine("\\10.1.10.5\NonConformance\Document\", Path.GetFileName(fileLocation)), True)
'THIS WILL SAVE A FILE PATH TO THE ACCESS DB
Using cmd As New OleDbCommand(SqlString1, conn)
'cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@incid", doc1.Text)
cmd.Parameters.AddWithValue("@docid", doc2.Text)
cmd.Parameters.AddWithValue("@FileName", Path.GetFileName(Me.OpenFileDialog1.FileName))
cmd.Parameters.AddWithValue("@FilePath", "\\10.1.10.5\NonConformance\Document\" & Path.GetFileName(Me.OpenFileDialog1.FileName))
cmd.ExecuteNonQuery()
conn.Close()
End Using
End If
conn.Close()
End Using
I am concerned that if a user uploads a file with the same filename as one already in the folder it will cause issues when trying to retrieve information at a later date.
So can anyone tell me how to rename the file when copying it to the network location. Ideally I would like to rename it to be the @incid_@docid parameters