Question

How do I copy across a file to another location in c# and overwrite the file if it exists.

Here is what I have so far:

        string sitemap_path = "T:\\somefolder\\somefolder\\somefolder\\Sitemap.xml";
        string server_path ="X:\\somefolder\\somefolder\\somefolder";
        File.Copy(sitemap_path,server_path,true);
        Console.WriteLine();
        Console.ReadLine();
Was it helpful?

Solution

you have forgotten to give the file name in new path:

File.Copy(sitemap_path,server_path + "\\newFileName.xml", true);

OTHER TIPS

You also have to include the file name in the server path string not just the destination directory See:http://msdn.microsoft.com/en-us/library/9706cfs5(v=vs.110).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top