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. File being used

File being used

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

    hey guyz..im having a problem about my application, it has a profile form, with picture, this picture is being converted to bytes and save it to database, when the form loads, it will create a temporary file..and display the picture.. but the problem here is that, whenever i changed the picture of a certain profile, it will still displays the previous one, because the "file is being used". I can't see the effect, unless i stop the application and run it again.. i hope you can help me with this..tnx in advance some codes: strfn = AppDomain.CurrentDomain.BaseDirectory + "profile_pic\\" + dgProfile[dgProfile.CurrentRowIndex,0].ToString(); FileStream fs = new FileStream(strfn,FileMode.Create,FileAccess.Write); fs.Write(imageByte,0,imageByte.Length); fs.Flush(); fs.Close(); picBoxProfile.Image = Image.FromFile(strfn);

    C L 2 Replies Last reply
    0
    • S spy

      hey guyz..im having a problem about my application, it has a profile form, with picture, this picture is being converted to bytes and save it to database, when the form loads, it will create a temporary file..and display the picture.. but the problem here is that, whenever i changed the picture of a certain profile, it will still displays the previous one, because the "file is being used". I can't see the effect, unless i stop the application and run it again.. i hope you can help me with this..tnx in advance some codes: strfn = AppDomain.CurrentDomain.BaseDirectory + "profile_pic\\" + dgProfile[dgProfile.CurrentRowIndex,0].ToString(); FileStream fs = new FileStream(strfn,FileMode.Create,FileAccess.Write); fs.Write(imageByte,0,imageByte.Length); fs.Flush(); fs.Close(); picBoxProfile.Image = Image.FromFile(strfn);

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      How do you read the bitmap ? If you pass the path to the constructor, this is what's holding the file open.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      1 Reply Last reply
      0
      • S spy

        hey guyz..im having a problem about my application, it has a profile form, with picture, this picture is being converted to bytes and save it to database, when the form loads, it will create a temporary file..and display the picture.. but the problem here is that, whenever i changed the picture of a certain profile, it will still displays the previous one, because the "file is being used". I can't see the effect, unless i stop the application and run it again.. i hope you can help me with this..tnx in advance some codes: strfn = AppDomain.CurrentDomain.BaseDirectory + "profile_pic\\" + dgProfile[dgProfile.CurrentRowIndex,0].ToString(); FileStream fs = new FileStream(strfn,FileMode.Create,FileAccess.Write); fs.Write(imageByte,0,imageByte.Length); fs.Flush(); fs.Close(); picBoxProfile.Image = Image.FromFile(strfn);

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

        Hi, Image.FromFile() is known to lock the file for as long as the image is alive; I suggest you try and use Image.FromStream() instead. The stream you use can be a FileStream, but it can also be a MemoryStream, so maybe you don't need a file at all. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


        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