i faced an issue with downloading file from website.
A user can fill in the textbox (example: hello.html) and then click on a button to download the html file. Now my issue is: even the file “hello.html” is not exists, my code will tend to download it as well. There will be “index.html” file appears in folder. How do I write “if” statement so that I can tell the code not to download if the file is not exist?
My code:
if (FILE NOT EXIST ON THE WEBSITE)
{
//MessageBox.Show("There is no such file on the website. Please check your spelling.");
}
else
{
client.DownloadFile("http://example.com/" + txtbox.Text.ToUpper().ToString(),
sourceDir + txtbox.Text.ToUpper().ToString() + ".html");
}
Thank you so much.
System.IO.File.Exists(fpath) returns false in Chrome and Firefox
That problem is specific for uploading but its the same concept.
OR:
Taken Directly from: http://www.dotnetthoughts.net/how-to-check-remote-file-exists-using-c/
Add this method to your class.
Then when you want to check if a file exists at a url use this: