Tuesday, February 12, 2008

How to copy, move files in C# .Net

Use system.IO namespace

FileInfo myfile = new FileInfo(@"H:\myphoto.jpg");

if (myfile.Exists)
myfile.CopyTo(@"H:\myphoto.bak",true );

- If the second parameter is true, the existing file will be replaced.
- If we specify an invalid path in MoveTo() it will throw DirectoryNotFoundException.

No comments:

landscape paintings nature art landscape art sky art illustration art artwork art human art beautiful art landscape prints nature prints sky prints illustration prints artwork prints human prints beautiful prints beautiful special promotions nature special promotions sky special promotions illustration special promotions artwork special promotions beautiful canvas prints beautiful painting canvas prints beautiful framed prints beautiful painting framed prints beautiful posters beautiful painting posters