Victor Charles
asked on
Help with modifying file name before saving to folder.
Hello,
I am using the code below to modify the filename of an image and assign it to C1Image.text, how do I modify the code to also save the file to my application's folder with the same modified filename? For example image name I want to upload Image1.jpg
I need to save it as Image1_ManufactureNmae_Cou ntry.jpg to C1Image.text and also to my application's folder. Problem with the code is it is saving the original filename to my application's folder.
Dim DestinationPath As String = IO.Path.Combine(Applicatio n.StartupP ath & "\Images", IO.Path.GetFileName(C1Imag e.Text))
If IO.File.Exists(Destination Path) Then
If MessageBox.Show("Destinati on already exists!" & vbCrLf & vbCrLf & "File: " & DestinationPath, "Replace File?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult .Yes Then
IO.File.Copy(C1Image.Text, DestinationPath, True)
End If
Else
IO.File.Copy(C1Image.Text, DestinationPath)
End If
If C1Manufacturer.Text <> "" Then
C1Image.Text = System.IO.Path.GetFileName WithoutExt ension(Ope nFileDialo g1.FileNam e) & "_" & C1Manufacturer.Text & C1CountryOrigin.Text & System.IO.Path.GetExtensio n(OpenFile Dialog1.Fi leName)
End If
If C1Manufacturer.Text = "" Or C1Manufacturer.Text = "Select/Enter" Then
MsgBox("Manufacturer must be included before saving image")
End If
BtnSave.Enabled = False
Thanks,
Victor
I am using the code below to modify the filename of an image and assign it to C1Image.text, how do I modify the code to also save the file to my application's folder with the same modified filename? For example image name I want to upload Image1.jpg
I need to save it as Image1_ManufactureNmae_Cou
Dim DestinationPath As String = IO.Path.Combine(Applicatio
If IO.File.Exists(Destination
If MessageBox.Show("Destinati
IO.File.Copy(C1Image.Text,
End If
Else
IO.File.Copy(C1Image.Text,
End If
If C1Manufacturer.Text <> "" Then
C1Image.Text = System.IO.Path.GetFileName
End If
If C1Manufacturer.Text = "" Or C1Manufacturer.Text = "Select/Enter" Then
MsgBox("Manufacturer must be included before saving image")
End If
BtnSave.Enabled = False
Thanks,
Victor
To rename a file, you need to use the File.Move function by supplying it the old and new names.
ASKER
I will try to figure it out and get back to you tomorrow.
Thanks,
V.
Thanks,
V.
ASKER
Hi,
I managed to include the extension by moving
C1Image.Text = System.IO.Path.GetFileName WithoutExt ension(Ope nFileDialo g1.FileNam e) & "_" & C1Manufacturer.Text & C1CountryOrigin.Text & System.IO.Path.GetExtensio n(OpenFile Dialog1.Fi leName)
on top of the code.
but now receiving the following error:
Conversion from string "Application.StartupPath & " to type 'Long' is not valid.
On line
IO.File.Copy("Application. StartupPat h & " \ "Images" \ " + C1Image.Text", DestinationPath)
code:
C1Image.Text = System.IO.Path.GetFileName WithoutExt ension(Ope nFileDialo g1.FileNam e) & "_" & C1Manufacturer.Text & C1CountryOrigin.Text & System.IO.Path.GetExtensio n(OpenFile Dialog1.Fi leName)
Dim DestinationPath As String = IO.Path.Combine(Applicatio n.StartupP ath & "\Images", IO.Path.GetFileName(C1Imag e.Text))
If IO.File.Exists(Destination Path) Then
If MessageBox.Show("Destinati on already exists!" & vbCrLf & vbCrLf & "File: " & DestinationPath, "Replace File?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult .Yes Then
IO.File.Copy(C1Image.Text, DestinationPath, True)
End If
Else
IO.File.Copy(C1Image.Text, DestinationPath)
End If
If C1Manufacturer.Text <> "" Then
End If
If C1Manufacturer.Text = "" Or C1Manufacturer.Text = "Select/Enter" Then
MsgBox("Manufacturer must be included before saving image")
End If
BtnSave.Enabled = False
How do I fix this error?
Thanks,
Victor
I managed to include the extension by moving
C1Image.Text = System.IO.Path.GetFileName
on top of the code.
but now receiving the following error:
Conversion from string "Application.StartupPath & " to type 'Long' is not valid.
On line
IO.File.Copy("Application.
code:
C1Image.Text = System.IO.Path.GetFileName
Dim DestinationPath As String = IO.Path.Combine(Applicatio
If IO.File.Exists(Destination
If MessageBox.Show("Destinati
IO.File.Copy(C1Image.Text,
End If
Else
IO.File.Copy(C1Image.Text,
End If
If C1Manufacturer.Text <> "" Then
End If
If C1Manufacturer.Text = "" Or C1Manufacturer.Text = "Select/Enter" Then
MsgBox("Manufacturer must be included before saving image")
End If
BtnSave.Enabled = False
How do I fix this error?
Thanks,
Victor
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You!