473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

File Created Not Accessible Until App Shuts Down

I am using the filestream feature in VB.NET to create a file. However, I am not able to delete or overwrite the file until the app closes down. I am using the .Close( ) method on the filestream right after it is created. I am creating a .BMP file from an OLE Object of an Access database field. After creating the .BMP file, I read it back into a System.Drawing.Image object (in order to display the bitmap on my form), using the " FromFile('c:\sign.bmp')" method (and have also used " = New Bitmap('c:\sign.bmp')" as well). It is this command that puts some kind of lock on the file - with that remarked out, I can do anything with the file I want to. Here is a code snippet
----------------------------------------------------------------
Dim imgSignature As System.Drawing.Imag
Dim imgData() As Byt

imgData = dr.Item("StudentSign"
Dim fs As New FileStream("c:\sign.bmp", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite
fs.Write(imgData, 0, UBound(imgData)
fs.Close(
fs = Nothin
picSignature.Image = imgSignature.FromFile("c:\sign.bmp"
imgSignature = Nothin
----------------------------------------------------------------

Once that " = imgSignature.FromFile('c:\sign.bmp')" code is executed, the sign.bmp file is inaccessible (cannot be deleted either programatically or through Windows Explorer). I tried to use "imgSignature.Dispose()", and that caused argument errors just trying to start the application

Any ideas

- Thanks

JR

Nov 20 '05 #1
7 1402
* "=?Utf-8?B?Sm9obiBEb3VnaGVydHk=?=" <an*******@discussions.microsoft.com> scripsit:
I am using the filestream feature in VB.NET to create a file. However, I am not able to delete or overwrite the file until the app closes down. I am using the .Close( ) method on the filestream right after it is created. I am creating a .BMP file from an OLE Object of an Access database field. After creating the .BMP file, I read it back into a System.Drawing.Image object (in order to display the bitmap on my form), using the " FromFile('c:\sign.bmp')" method (and have also used " = New Bitmap('c:\sign.bmp')" as well). It is this command that puts some kind of lock on the file - with that remarked out, I can do anything with the file I want to. Here is a code snippet:
-----------------------------------------------------------------
Dim imgSignature As System.Drawing.Image
Dim imgData() As Byte

imgData = dr.Item("StudentSign")
Dim fs As New FileStream("c:\sign.bmp", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)
fs.Write(imgData, 0, UBound(imgData))
fs.Close()
fs = Nothing
picSignature.Image = imgSignature.FromFile("c:\sign.bmp")
imgSignature = Nothing
-----------------------------------------------------------------

Once that " = imgSignature.FromFile('c:\sign.bmp')" code is executed, the sign.bmp file is inaccessible (cannot be deleted either programatically or through Windows Explorer). I tried to use "imgSignature.Dispose()", and that caused argument errors just trying to start the application.


Does 'imgSignature.Dispose()' help?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
> > Once that " = imgSignature.FromFile('c:\sign.bmp')" code is executed,
the sign.bmp file is inaccessible (cannot be deleted either programatically
or through Windows Explorer). I tried to use "imgSignature.Dispose()", and
that caused argument errors just trying to start the application.

Does 'imgSignature.Dispose()' help?


Are you sure of this answer?

Cor
Nov 20 '05 #3
* "Cor Ligthert" <no**********@planet.nl> scripsit:
Once that " = imgSignature.FromFile('c:\sign.bmp')" code is executed,

the sign.bmp file is inaccessible (cannot be deleted either programatically
or through Windows Explorer). I tried to use "imgSignature.Dispose()", and
that caused argument errors just trying to start the application.

Does 'imgSignature.Dispose()' help?


Are you sure of this answer?


Yes, but it won't really solve the OP's problem.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
Hi Herfried,

Again, a little bit shorten
I tried to use "imgSignature.Dispose()", and
>that caused argument errors just trying to start the application.

Does 'imgSignature.Dispose()' help?


Are you sure of this answer?


Yes, but it won't really solve the OP's problem.


Cor
Nov 20 '05 #5
On Tue, 20 Apr 2004 12:01:04 -0700, John Dougherty wrote:
I am using the filestream feature in VB.NET to create a file. However, I am not able to delete or overwrite the file until the app closes down. I am using the .Close( ) method on the filestream right after it is created. I am creating a .BMP file from an OLE Object of an Access database field. After creating the .BMP file, I read it back into a System.Drawing.Image object (in order to display the bitmap on my form), using the " FromFile('c:\sign.bmp')" method (and have also used " = New Bitmap('c:\sign.bmp')" as well). It is this command that puts some kind of lock on the file - with that remarked out, I can do anything with the file I want to. Here is a code snippet:


Try loading the .bmp using a FileStream and then use the image object's
FromStream method.
--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #6
Hi Chris,

I sended this already to someone else today, did you see this sample from me
before.
The XML file is representing the database however is not important what
databas, when it is for a Ole embeded image from a non 97 access database
it needs a little extention, that I have also.

Cor

\\\
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Reading a picture and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
'writing a picture from a bytearray
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
'writing a bytearray to a dataset
Dim ds As New DataSet
ds.Tables.Add(New DataTable("Photo"))
ds.Tables(0).Columns.Add(New DataColumn("Sample"))
ds.Tables(0).Columns(0).DataType =
System.Type.GetType("System.Byte[]")
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0) = abyt
Dim sf As New SaveFileDialog
If sf.ShowDialog = DialogResult.OK Then
ds.WriteXml(sf.FileName, XmlWriteMode.WriteSchema)
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'reading a picture from a dataset
Dim ds As New DataSet
If fo.ShowDialog = DialogResult.OK Then
ds.ReadXml(fo.FileName)
End If
abyt = CType(ds.Tables(0).Rows(0)(0), Byte())
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
///
Nov 20 '05 #7
Thanks for the help, Chris! Your idea took care of the problem. I changed to use a 2nd filestream to read the .BMP image
back into my image control, and now the file can be deleted

Dim fs2 As New FileStream("c:\sign.bmp", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite
Dim imgData2(fs2.Length() - 1) As Byt
fs2.Read(imgData2, 0, fs2.Length
picSignature.Image = imgSignature.FromStream(fs2
fs2.Close(
fs2 = Nothin

So apparently, using the filestream, rather than the FromFile method, doesn't put some kind of lock on the file (or whatever it was doing!)

- JRD
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Bob Darlington | last post by:
I have a repair and backup database routine which runs when a user closes down my application. It works fine in my development machine, but breaks on a client's at the following line: If...
6
by: Kiran | last post by:
Hi, I have program, which opens file at the startup and logs error messages to the file, file handle is closed at the end of the program. However if file is deleted in-between, program do not...
3
by: Tarun Jain | last post by:
Hi, I am trying to create a WebService which uses data stored in a large xml file (200-400 MB). Obviously parsing the xml for every webservice request is not feasible since that would make the...
6
by: Don | last post by:
I'm having problems working with a streamwriter object. After closing the streamwriter and setting it to Nothing, I try to delete the file it was writing to, but I always get the following error...
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
2
by: TDC | last post by:
I'm working on tying in a library that uses a TcpClient/NetworkStream/BeginRead. When that lib object is started, it connects and immediately does a BeginRead that stays pending until the socket...
13
by: Tony Girgenti | last post by:
Hello. I developed a web consuming windows application/form program with VS.NET 2003, VB, .Net Framework 1.1.4322, ASP.NET 1.1.4322, IIS 5.1. Using this code to open a simple text file. If i...
9
by: Matt | last post by:
How would I do this ... I want to set the Windows Scheduler to run the ..bat file which will open an access database at like 2 in the AM. What code do I need in the .bat file.
1
by: TC | last post by:
I'm experiencing an unusual problem. When I run a specific make-table query on a computer, that computer shuts down. The computer shuts down completely, without warning, as if a power failure...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.