Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello Guys, please I need to rename this file after it has been copied to the folder specified. I need to be renamed to a value inside a textbox. I would really appreciate your help.

C#
private void UploadPassportbutton_Click(object sender, EventArgs e)
        {
            // open file dialog
            OpenFileDialog getPassport = new OpenFileDialog();
            getPassport.Multiselect = false;
            getPassport.Title = "Select Passport Photograph";

            // image filters
            getPassport.Filter = "Image Files(*.png; *.PNG)|*.png; *.PNG";
            if (getPassport.ShowDialog() == DialogResult.OK)
            {
                //sets the new file path
                string newPath = Path.Combine(@"\\QUBE\Pics\", Path.GetFileName(getPassport.FileName));
                PassportpictureBox.Image = Image.FromFile(getPassport.FileName);

                //check if fileexists
                if (File.Exists(newPath))
                {
                    //You could rename the file
                    MessageBox.Show("That image already exists...", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    File.Copy(getPassport.FileName, newPath);
                }
            }
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900