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. Access denied...

Access denied...

Scheduled Pinned Locked Moved C#
question
7 Posts 3 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.
  • S Offline
    S Offline
    simplicitylabs
    wrote on last edited by
    #1

    I'm attempting to write a file to a removable drive. When the app gets to the point where it creates the StreamWriter, it's stops and tells me access to the *whatever*:\ drive denied. I have administrator rights, and have also given the app admin rights by "running as admin". Is there something I should be doing besides the usual to get this working? Is what I'm doing correct?

        private void button1\_Click(object sender, EventArgs e)
        {
            string usbDriveLetter = listBox1.SelectedItem.ToString();
            string sPath = usbDriveLetter;
            sPath = usbDriveLetter.ToString();
            StreamWriter sw = new StreamWriter(sPath);
    
        ...and so on
    

    Thank you for your input.

    S M 2 Replies Last reply
    0
    • S simplicitylabs

      I'm attempting to write a file to a removable drive. When the app gets to the point where it creates the StreamWriter, it's stops and tells me access to the *whatever*:\ drive denied. I have administrator rights, and have also given the app admin rights by "running as admin". Is there something I should be doing besides the usual to get this working? Is what I'm doing correct?

          private void button1\_Click(object sender, EventArgs e)
          {
              string usbDriveLetter = listBox1.SelectedItem.ToString();
              string sPath = usbDriveLetter;
              sPath = usbDriveLetter.ToString();
              StreamWriter sw = new StreamWriter(sPath);
      
          ...and so on
      

      Thank you for your input.

      S Offline
      S Offline
      sam
      wrote on last edited by
      #2

      check!!may be your flash drive is write protected

      S 1 Reply Last reply
      0
      • S sam

        check!!may be your flash drive is write protected

        S Offline
        S Offline
        simplicitylabs
        wrote on last edited by
        #3

        Nope. Not write protected. I'm wondering, in the code I'm opening StreamWriter, but not actually writing anything yet. Could this be the problem?

        S 1 Reply Last reply
        0
        • S simplicitylabs

          I'm attempting to write a file to a removable drive. When the app gets to the point where it creates the StreamWriter, it's stops and tells me access to the *whatever*:\ drive denied. I have administrator rights, and have also given the app admin rights by "running as admin". Is there something I should be doing besides the usual to get this working? Is what I'm doing correct?

              private void button1\_Click(object sender, EventArgs e)
              {
                  string usbDriveLetter = listBox1.SelectedItem.ToString();
                  string sPath = usbDriveLetter;
                  sPath = usbDriveLetter.ToString();
                  StreamWriter sw = new StreamWriter(sPath);
          
              ...and so on
          

          Thank you for your input.

          M Offline
          M Offline
          Martin 0
          wrote on last edited by
          #4

          HEllo, I don't think that a drive letter is a correct path argument for the StreamWriter Constructor. You should use a path to a file! All the best, Martin

          S 1 Reply Last reply
          0
          • S simplicitylabs

            Nope. Not write protected. I'm wondering, in the code I'm opening StreamWriter, but not actually writing anything yet. Could this be the problem?

            S Offline
            S Offline
            sam
            wrote on last edited by
            #5

            I think proplem is occuring because you are not providing any file name try to write like this string sPath = usbDriveLetter; sPath = usbDriveLetter.ToString()+"\\myFile.txt"; StreamWriter sw = new StreamWriter(sPath);

            1 Reply Last reply
            0
            • M Martin 0

              HEllo, I don't think that a drive letter is a correct path argument for the StreamWriter Constructor. You should use a path to a file! All the best, Martin

              S Offline
              S Offline
              simplicitylabs
              wrote on last edited by
              #6

              Even if the file doesn't exist yet? If that's the problem, boy do I feel like an idiot.

              M 1 Reply Last reply
              0
              • S simplicitylabs

                Even if the file doesn't exist yet? If that's the problem, boy do I feel like an idiot.

                M Offline
                M Offline
                Martin 0
                wrote on last edited by
                #7

                simplicitylabs wrote:

                Even if the file doesn't exist yet?

                Yes

                simplicitylabs wrote:

                If that's the problem, boy do I feel like an idiot

                You shouldn't. But MSDN is your friend at this kind of proplems: http://msdn2.microsoft.com/en-us/library/36b035cb.aspx[^] All the best, Martin

                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