Reputation: 113
Hi all is it possible to copy a file from the path obtained to the domain, I tried as follows but I am getting an exception as uri formats are not supported
.. So can some one help me how to copy the file
string filePath = "D:\\Folder\\filename.jpg";
FileInfo fileInfo = new FileInfo(filePath);
if (fileInfo.Exists)
{
path = "http://WWW.somedomain.com";
string temppath = path + "/Temp" + "/" + fileInfo.Name;
if (!File.Exists(temppath))
{
var uri = new Uri(temppath);
File.Copy(filePath, uri.AbsoluteUri);
}
Upvotes: 0
Views: 72
Reputation: 40970
You want to check the existence of file on the server. This is not possible using File.Exist
method as it doesn't supports the URI. This method expect the relative path and checked the existence on machine (physical location).
In this case you should use WebRequest
and get the response from the server. If server returns 404 then your file doesn't exist on the serve or you can check the Content Length.
WebRequest request = WebRequest.Create(new Uri(temppath));
request.Method = "HEAD";
WebResponse response = request.GetResponse()
var contentLength = response.ContentLength;
if (contentLength < 0)
{
// file doesn't exist.
}
Upvotes: 1