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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem Uploading an Image twice [modified]

Problem Uploading an Image twice [modified]

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netsysadminhelpquestion
3 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.
  • B Offline
    B Offline
    Britney S Morales
    wrote on last edited by
    #1

    Guys i get a ioexception when try to upload an image twice. Here the process. The first time that i upload the image is sucessfull. if the user try to upload the same image again , with the same name, the server will try to rewrite the image saved on the server getting a ioexception X| . The Ioexception is, the file is being used by another process :confused:. I dont know whos using the image? in order to Kill that process, (if is the asp.net process, what i have to do?). Any Suggest? :sigh:

    keep Learning and you never will be out of date...

    K S 2 Replies Last reply
    0
    • B Britney S Morales

      Guys i get a ioexception when try to upload an image twice. Here the process. The first time that i upload the image is sucessfull. if the user try to upload the same image again , with the same name, the server will try to rewrite the image saved on the server getting a ioexception X| . The Ioexception is, the file is being used by another process :confused:. I dont know whos using the image? in order to Kill that process, (if is the asp.net process, what i have to do?). Any Suggest? :sigh:

      keep Learning and you never will be out of date...

      K Offline
      K Offline
      Kschuler
      wrote on last edited by
      #2

      The "who" who is using the image is probably you the first time you uploaded. Make sure that you are properly disposing of objects that you use when dealing with the image. One of them must still be holding on to the image file. I've done had this problem before when using a System.Drawing.Image object in my code to deal with a file. After you are done with it you must dispose it to get it to release it's hold on the file. This is my example: Dim x as System.Drawing.Image x= Drawing.Image.FromFile(strMyImageFilePath) x.Dispose() Hope this helps.

      1 Reply Last reply
      0
      • B Britney S Morales

        Guys i get a ioexception when try to upload an image twice. Here the process. The first time that i upload the image is sucessfull. if the user try to upload the same image again , with the same name, the server will try to rewrite the image saved on the server getting a ioexception X| . The Ioexception is, the file is being used by another process :confused:. I dont know whos using the image? in order to Kill that process, (if is the asp.net process, what i have to do?). Any Suggest? :sigh:

        keep Learning and you never will be out of date...

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

        hi:laugh: try this code public void OnUpload(Object sender, EventArgs e) { // Create a byte[] from the input file int len = Upload.PostedFile.ContentLength; byte[] pic = new byte[len]; Upload.PostedFile.InputStream.Read (pic, 0, len); // Insert the image and comment into the database SqlConnection connection = new SqlConnection (@"server=INDIA\INDIA;database=iSense;uid=sa;pwd=india"); try { connection.Open (); SqlCommand cmd = new SqlCommand ("insert into Image " + "(Picture, Comment) values (@pic, @text)", connection); cmd.Parameters.Add ("@pic", pic); cmd.Parameters.Add ("@text", Comment.Text); cmd.ExecuteNonQuery (); } finally { connection.Close (); } } and try this link also http://www.codeproject.com/aspnet/PicManager.asp regards saravanan:laugh:

        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