Help with modifying file name before saving to folder.
Posted on 2013-01-15
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_Country.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(Application.StartupPath & "\Images", IO.Path.GetFileName(C1Image.Text))
If IO.File.Exists(DestinationPath) Then
If MessageBox.Show("Destination already exists!" & vbCrLf & vbCrLf & "File: " & DestinationPath, "Replace File?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
IO.File.Copy(C1Image.Text, DestinationPath, True)
If C1Manufacturer.Text <> "" Then
C1Image.Text = System.IO.Path.GetFileNameWithoutExtension(OpenFileDialog1.FileName) & "_" & C1Manufacturer.Text & C1CountryOrigin.Text & System.IO.Path.GetExtension(OpenFileDialog1.FileName)
If C1Manufacturer.Text = "" Or C1Manufacturer.Text = "Select/Enter" Then
MsgBox("Manufacturer must be included before saving image")
BtnSave.Enabled = False