Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8561017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:24:27+00:00 2026-06-11T16:24:27+00:00

i faced an issue with downloading file from website. A user can fill in

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:24:28+00:00Added an answer on June 11, 2026 at 4:24 pm

    System.IO.File.Exists(fpath) returns false in Chrome and Firefox

    if (File.Exists(fileLocation))
    { 
        // Download File!
    }
    

    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.

    private bool RemoteFileExists(string url)
    {
        try
        {
            //Creating the HttpWebRequest
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            //Setting the Request method HEAD, you can also use GET too.
            request.Method = "HEAD";
            //Getting the Web Response.
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            //Returns TURE if the Status code == 200
            return (response.StatusCode == HttpStatusCode.OK);
        }
        catch
        {
            //Any exception will returns false.
            return false;
        }
    }
    

    Then when you want to check if a file exists at a url use this:

    if (RemoteFileExists("http://blog.stackoverflow.com/wp-content/uploads/stackoverflow-logo-300.png")
    {
        //File Exists
    }
    else
    {
        //File does not Exist
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We faced an issue with file Merge at TFS2010. Until now, we merged files
When downloading file from server if i use a4j:commandLink file download fail(mean file written
I was writing a code using malloc for something and then faced a issue
I faced following issue with my work: having two projects: MFC .dll and MFC
I faced one issue while working on a C code with Microsoft Visual Studio-2005
Recently we faced the issue of flowscope values not being set across the flow,
When I deployed my application on the server I faced this issue: Request.Url.ToString(); returns
I' ve been doing some programming lately and faced an issue which i found
I faced the following issue while I submitting my form using jQuery FORM and
I am faced with the following issue and at this point I feel like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.