File being used
-
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);
-
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);
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 )
-
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);
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