简体   繁体   中英

C# How to Rename file after File.Copy without using File.Move

I'm Working on a module where I need to copy a file to FTP path using C#. From there FTP will start processing that file based on name and extension. My Problem is while copying a huge file to the path FTP Picked up that file for processing before copying process get completed. To overcome this issue I changed the file name and extension and done with the file copy.

Now I need to rename the file with Original name. Is there any way in C# to rename the file without using File.Move ?

Thanks.

Usually you´ll have to use File.Move to accomplish this task. It is the easier approach.

If, for whatever reason you don´t want to use it, you can do it this way (you will have to reference Microsoft.VisualBasic):

Microsoft.VisualBasic.FileIO.FileSystem.RenameFile(myfile, newName);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM