How can we copy the file from one location to other?

 Posted by Lakhangarg on 11/4/2009 | Category: ASP.NET Interview questions | Views: 4276

Using File.Copy Method we can copy the file from one location to other.

System.IO.File.Copy("Source File Path", "Destination File Path");

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Raja on: 11/4/2009
Dear you should provide complete related information about this. Like the source and destination file path will be like phyiscal path not virtual path.

Just to add
Server.MapPath("/root/myfolder") will give the physical path of the folder from starting from the driver letter that can be used in place of "Source File Path" and "Destination File Path".

So the ammended code snippet may look like

System.IO.File.Copy(Server.MapPath("/root/source/a.xml"), Server.MapPath("/root/destination/b.xml"));

Thank you.

Lakhan, please do not mind, just an effort to provide complete info :)

Posted by: Lakhangarg on: 11/4/2009
Good Effort Raja, Thanks :)

Login to post response