Results 1 to 2 of 2

Thread: Download file using webclient credentials

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2003
    Posts
    23

    Download file using webclient credentials

    Hey guys, kinda new to C#. I have searched the forums a bit and havent found my answer.
    My question is.....I would like to download a file from an https site and save it to a network location. I am prompted for credentials when logging in.
    Any thoughts?


    Thanks


    I have tried it this way.

    private void button1_Click(object sender, EventArgs e)
    {
    string username = "MyUsername";
    string password = "MyPassword";
    string domain = "MyDomain";
    string MyFile = @"c:\File.xsn";
    string MyURL = "https://qaTestSite/XSN/File.xsn";

    System.Net.WebClient Client = new WebClient();

    Client.Credentials = new NetworkCredential(username, password, domain);
    Client.DownloadFile(MyURL,MyFile);
    MessageBox.Show("File Downloaded!");
    }
    A newbie, just trying to learn his way and get by.

  2. #2

    Re: Download file using webclient credentials

    You may have to use a URIBuilder

    Code:
    URIBuilder uriBuild = new URIBulder();
    uriBuild.UserName = "username";
    uriBuild.Password = "password";
    uriBuild.Host = "www.hostwherefileis.com";
    uriBuild.Path = "/XSN/File.xsn";
    
    Client.DownloadFile(uriBuild.uri, "C:\myfile.xsn");

    Hope that helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width