Click here to Skip to main content
15,891,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to copy a file to another folder i want to change the name of that file before saving to destination folder
i am using this code for copying

C#
OpenFileDialog op1 = new OpenFileDialog();
           op1.Multiselect = true;
           op1.ShowDialog();
           op1.Filter = "allfiles|*.txt";
           textBox1.Text = op1.FileName;

           int count = 0;
           string[] FName;
           foreach (string s in op1.FileNames)
           {
               FName = s.Split('\\');
               //FileInfo fInfo = new FileInfo(textBox1.Text);
               //fInfo.MoveTo(Macadd.Text);

               File.Copy(s, "\\\\100.3.10.11\\FileDump\\" + FName[FName.Length - 1]);


               count++;
           }
           MessageBox.Show(Convert.ToString(count) + " File Saved Successfully ");
Posted

Use File.Move[^]
 
Share this answer
 
Comments
$ultaNn 24-Oct-13 7:05am    
i want to rename the file on destination folder before saving
OriginalGriff 24-Oct-13 7:26am    
Yes - use File.Move, and specify the destination file (existing) and the same folder plus the new name. That renames the existing file, then you can copy the new version over.
C#
string a;
            a = (Macadd.Text + ".txt");
            File.Copy(s, "\\\\100.43.100.101\\FileDump\\" + a);//+ FName[FName.Length - 1]);
            count++;
        }
 
Share this answer
 
Hope this link will useful for you for renaming files.

http://stackoverflow.com/questions/680786/rename-files-name-in-a-folder/680802#680802[^]


--SDK
 
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