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. PictureBox Problem

PictureBox Problem

Scheduled Pinned Locked Moved C#
helpdatabase
6 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.
  • T Offline
    T Offline
    The_Soul_Of_Rock
    wrote on last edited by
    #1

    the problem is here: string currentPath; private void frmPicture_Load(object sender, System.EventArgs e) { currentPath = @"D:\Image\1.jpg"; this.pictureBox1.Image = Image.FromFile(currentPath); } private void updateButton_Click(object sender, System.EventArgs e) { if (File.Exists(currentPath)) { string newPath = Application.StartupPath + @"\PatientImages\" + arrISN[index].ToString() + ext; this.pictureBox1.Image = null; File.Copy(currentPath, newPath, true); } } Error: the process cannot access the file "D:\.." because it is being used by another process. what can i do to correct this problem. thanks. Rock Throught The Night

    E H 3 Replies Last reply
    0
    • T The_Soul_Of_Rock

      the problem is here: string currentPath; private void frmPicture_Load(object sender, System.EventArgs e) { currentPath = @"D:\Image\1.jpg"; this.pictureBox1.Image = Image.FromFile(currentPath); } private void updateButton_Click(object sender, System.EventArgs e) { if (File.Exists(currentPath)) { string newPath = Application.StartupPath + @"\PatientImages\" + arrISN[index].ToString() + ext; this.pictureBox1.Image = null; File.Copy(currentPath, newPath, true); } } Error: the process cannot access the file "D:\.." because it is being used by another process. what can i do to correct this problem. thanks. Rock Throught The Night

      E Offline
      E Offline
      exhaulted
      wrote on last edited by
      #2

      I assume it's the File.Copy line that throws the error? Out of interest, you've not got the picture your copying open in another application have you? KP

      T 1 Reply Last reply
      0
      • E exhaulted

        I assume it's the File.Copy line that throws the error? Out of interest, you've not got the picture your copying open in another application have you? KP

        T Offline
        T Offline
        The_Soul_Of_Rock
        wrote on last edited by
        #3

        i known the error is File.Copy line but i cannot find out the to correct it. please help me again thanks Rock Throught The Night

        1 Reply Last reply
        0
        • T The_Soul_Of_Rock

          the problem is here: string currentPath; private void frmPicture_Load(object sender, System.EventArgs e) { currentPath = @"D:\Image\1.jpg"; this.pictureBox1.Image = Image.FromFile(currentPath); } private void updateButton_Click(object sender, System.EventArgs e) { if (File.Exists(currentPath)) { string newPath = Application.StartupPath + @"\PatientImages\" + arrISN[index].ToString() + ext; this.pictureBox1.Image = null; File.Copy(currentPath, newPath, true); } } Error: the process cannot access the file "D:\.." because it is being used by another process. what can i do to correct this problem. thanks. Rock Throught The Night

          E Offline
          E Offline
          exhaulted
          wrote on last edited by
          #4

          I have just tried the code with some adjustments for my file structure and it works fine. The only difference between my code and yours is the newpath string, i set mine to @"c:\golfball2.bmp" and when i clicked the update button i got a copy of golfball.bmp called golfball2.bmp. I assume the problem is that the destination for your file is currently being used by another application, or even by your application. Try hard coding the newPath string to @"c:\test.jpg". If that works then you will have to look at where your trying to write the copy to. Let me know how you get on. KP

          T 1 Reply Last reply
          0
          • E exhaulted

            I have just tried the code with some adjustments for my file structure and it works fine. The only difference between my code and yours is the newpath string, i set mine to @"c:\golfball2.bmp" and when i clicked the update button i got a copy of golfball.bmp called golfball2.bmp. I assume the problem is that the destination for your file is currently being used by another application, or even by your application. Try hard coding the newPath string to @"c:\test.jpg". If that works then you will have to look at where your trying to write the copy to. Let me know how you get on. KP

            T Offline
            T Offline
            The_Soul_Of_Rock
            wrote on last edited by
            #5

            the " currentPath " and the newPath is the same Folder and the " currentFileName " and "newFileName" is the same too so the error occur. Rock Throught The Night

            1 Reply Last reply
            0
            • T The_Soul_Of_Rock

              the problem is here: string currentPath; private void frmPicture_Load(object sender, System.EventArgs e) { currentPath = @"D:\Image\1.jpg"; this.pictureBox1.Image = Image.FromFile(currentPath); } private void updateButton_Click(object sender, System.EventArgs e) { if (File.Exists(currentPath)) { string newPath = Application.StartupPath + @"\PatientImages\" + arrISN[index].ToString() + ext; this.pictureBox1.Image = null; File.Copy(currentPath, newPath, true); } } Error: the process cannot access the file "D:\.." because it is being used by another process. what can i do to correct this problem. thanks. Rock Throught The Night

              H Offline
              H Offline
              Heath Stewart
              wrote on last edited by
              #6

              Either clone (via Clone - don't forget to cast it to an Image) the Image you get from Image.FromFile, or use a FileStream and specify FileShare.Read at the very least, then read the image from the stream (the Bitmap class - a derivative of Image - accepts a Stream as a parameter).

              Microsoft MVP, Visual C# My Articles

              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