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)
var pyEngine = Python.CreateEngine();
var paths = pyEngine.GetSearchPaths();
pyEngine.Execute("import shutil\n" +
"shutil.copyfile('" + from + "', '" + to + "')");
you can use a webclient and then get the file on a particular folder.
using (WebClient wc = new WebClient()) wc.DownloadFile("http://sitec.com/web/myfile.jpg", @"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("http://sitetocheck.com"); var response = http.GetResponse(); var stream = response.GetResponseStream(); var sr = new StreamReader(stream); var content = sr.ReadToEnd();