Marek Czaplicki Marek Czaplicki - 29 days ago 8
C# Question

Copy file from URI format path to local path

I am trying to copy a file which is on a server and all I've got is it's URI format path.

I've been trying to implement copying in C# .NET 4.5, but seems like CopyFile is not good with handling URI formats.

So I've used IronPython with shutil, but seems like it is also not good with URI format paths.

How do I get that file local?

private string CopyFile(string from, string to, string pythonLibDir, string date)
var dateTime = DateTime.Today;
if (dateTime.ToString("yy-MM-dd") == date)
return "";
var pyEngine = Python.CreateEngine();
var paths = pyEngine.GetSearchPaths();
pyEngine.Execute("import shutil\n" +
"shutil.copyfile('" + from + "', '" + to + "')");
return dateTime.ToString("yy-MM-dd");

I take all paths from xml config file.


you can use a webclient and then get the file on a particular folder.

using (WebClient wc = new WebClient())
    wc.DownloadFile("", @"c:\images\xyz.jpg");

or you can also use: HttpWebRequest inc ase you just want to read the content from a file from a server.

var http = (HttpWebRequest)WebRequest.Create("");
var response = http.GetResponse();

var stream = response.GetResponseStream();
var sr = new StreamReader(stream);
var content = sr.ReadToEnd();