1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C# Webclient Error

Discussion in 'C, C++, C#' started by Krippleintime, Mar 1, 2011.

  1. Krippleintime

    Krippleintime Registered Member

    Joined:
    May 12, 2010
    Messages:
    96
    Likes Received:
    13
    Location:
    Graphic Location Unknown
    When I try to run my program I keep getting an error saying that the webclient does not have permissions to the folder which I want to save the downloaded file. I have tried numerous folders, running the program as admin, and also running C# as admin, still the same error. Would I still get the error if I download the file through a Stream instead?

    Here is my code:

    Code:
    WebClient client = new WebClient();
                client.DownloadFile(new Uri(dlurl), @"C:\");
                MessageBox.Show("Done");
    Any help would be great, can't seem to find a fix to this.
     
  2. indianbill007

    indianbill007 Jr. VIP Jr. VIP

    Joined:
    Jan 8, 2010
    Messages:
    4,813
    Likes Received:
    4,051
    Occupation:
    Making Money when the world is sleeping
    Location:
    Menlo Park - Next to Zuck
    client.DownloadFile(new Uri(dlurl), @"C:\");

    This line has the issue, and I guess you are in vista or win7.

    Change it to.


    client.DownloadFile(new Uri(dlurl), @"C:\temp");
     
    • Thanks Thanks x 1
  3. Krippleintime

    Krippleintime Registered Member

    Joined:
    May 12, 2010
    Messages:
    96
    Likes Received:
    13
    Location:
    Graphic Location Unknown
    hmmm, I have seen to solve the problem with the error when I run it as admin, but now the file is not holding any data. This is what I changed it to:

    Code:
    client.DownloadFile(new Uri(dlurl), @"C:\file.exe");
    And when I run it all I get is a CMD prompt which keeps popping up some weird errors.

    Thanks for helping me with my main problem though!
     
  4. indianbill007

    indianbill007 Jr. VIP Jr. VIP

    Joined:
    Jan 8, 2010
    Messages:
    4,813
    Likes Received:
    4,051
    Occupation:
    Making Money when the world is sleeping
    Location:
    Menlo Park - Next to Zuck
  5. hiderightnow

    hiderightnow Junior Member

    Joined:
    Jul 19, 2010
    Messages:
    104
    Likes Received:
    22
    Try completely disabling UAC if you're on Vista or 7 and try again. Is this consistent on XP as well as 7?