Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. WebClient/ Access Denied upon saving file...?

WebClient/ Access Denied upon saving file...?

Scheduled Pinned Locked Moved C#
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jas0n23
    wrote on last edited by
    #1

    Hi all! :-D I was just wondering how I could elevate privelages programmatically using C# as I am trying to download a file from my site and automatically save it to My Documents on my computer but I keep getting an exception and it says access to MyDocuments denied. Does anybody know how to get around this? It happens on both my XP and Vista computers. I don't want to turn off UAC or the equivelant in XP either? I'd appreciate any advice I can get. Thanks in advance. Jay. P.S. Incase anybody wants to know how to download files using WebClient, here's the code:

    WebClient DownloadClient = new WebClient();
    DownloadClient.DownloadFile(StartingPointTextBox.Text, SaveSessionTextBox.Text);

    j.t.

    L 1 Reply Last reply
    0
    • J jas0n23

      Hi all! :-D I was just wondering how I could elevate privelages programmatically using C# as I am trying to download a file from my site and automatically save it to My Documents on my computer but I keep getting an exception and it says access to MyDocuments denied. Does anybody know how to get around this? It happens on both my XP and Vista computers. I don't want to turn off UAC or the equivelant in XP either? I'd appreciate any advice I can get. Thanks in advance. Jay. P.S. Incase anybody wants to know how to download files using WebClient, here's the code:

      WebClient DownloadClient = new WebClient();
      DownloadClient.DownloadFile(StartingPointTextBox.Text, SaveSessionTextBox.Text);

      j.t.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, you don't need special privileges to write files into your own MyDocuments folder, this works just fine (tested on Vista):

      string ff=Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)+@"\\folder\\";
      Directory.CreateDirectory(ff);
      File.WriteAllText(ff+"aha.txt", "contents");
      

      Did you get an error in the path, resulting in a non-existing folder/subfolder? :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


      J 2 Replies Last reply
      0
      • L Luc Pattyn

        Hi, you don't need special privileges to write files into your own MyDocuments folder, this works just fine (tested on Vista):

        string ff=Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)+@"\\folder\\";
        Directory.CreateDirectory(ff);
        File.WriteAllText(ff+"aha.txt", "contents");
        

        Did you get an error in the path, resulting in a non-existing folder/subfolder? :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


        J Offline
        J Offline
        jas0n23
        wrote on last edited by
        #3

        Thanks for your reply/code :-), Here's the code that I have. I haven't forgotten any folders (I double checked after reading your message) and I'm completely baffled. I even try saving the file to the Desktop and about 15 other folders lol but it shows the same access denied error on both systems. Weird. I've never had this happen before. Below, the StartingPointTextBox is where the file's downloaded from, and the SaveSessionTextBox is where it'll be saved to:

        DownloadClient.DownloadFile(StartingPointTextBox.Text, SaveSessionTextBox.Text);

        In my application, I have a FolderBrowserDialog appear that lets me choose where to save the downloaded file to. Jay.

        j.t.

        L 1 Reply Last reply
        0
        • J jas0n23

          Thanks for your reply/code :-), Here's the code that I have. I haven't forgotten any folders (I double checked after reading your message) and I'm completely baffled. I even try saving the file to the Desktop and about 15 other folders lol but it shows the same access denied error on both systems. Weird. I've never had this happen before. Below, the StartingPointTextBox is where the file's downloaded from, and the SaveSessionTextBox is where it'll be saved to:

          DownloadClient.DownloadFile(StartingPointTextBox.Text, SaveSessionTextBox.Text);

          In my application, I have a FolderBrowserDialog appear that lets me choose where to save the downloaded file to. Jay.

          j.t.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi Jay, the code you are showing doesn't tell me anything, since the file path is to be read from a Control. AFAIK a FolderBrowserDialog returns the path to an existing folder, which is *not* the path of a file inside that folder. You can't overwrite a folder with a file. Try appending some relative file path (such as "aha.txt") and then save. FWIW: when something fails, make it log its intermediate values; as in Console.WriteLine("filespec="+f); That often is the fast way to spot what may be wrong. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


          1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, you don't need special privileges to write files into your own MyDocuments folder, this works just fine (tested on Vista):

            string ff=Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)+@"\\folder\\";
            Directory.CreateDirectory(ff);
            File.WriteAllText(ff+"aha.txt", "contents");
            

            Did you get an error in the path, resulting in a non-existing folder/subfolder? :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


            J Offline
            J Offline
            jas0n23
            wrote on last edited by
            #5

            Luc Pattyn, Thank you so much for your help and code I really appreciate it. Unfortunatly, I'm a little brain dead tonight as I just figured out that I was telling it to save to a folder, but I wasn't giving it a filename to save as lol. Regards, Jay.

            j.t.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups