473,387 Members | 1,495 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,387 software developers and data experts.

file downloaded using FileStream "in use by another process"

Hi there

I use the FileStream object to download a zip file over the internet to my
local disk. The file downloads successfully, but when I attempt to unzip it,
I'm told that the file is in use by another process. This occurs even if I
release the object using fs.Close() and fs = Nothing.

Please help (my code is given below)

Best regards
Loane

'Create a new filestream to receive data ...
Dim fs_App As FileStream = New FileStream("C:\app.zip", FileMode.Create)

'Instantiate a new byte variable to receive data ...
datBuffer = New Byte(1023) {}

'Create a webrequest/response ...
Dim reqSync_App As WebRequest = WebRequest.Create("http://123.com/app.zip")
Dim respSync_App As WebResponse = reqSync_App.GetResponse()

'Retrieve file details (ie. file length) ...
Dim strm_App As Stream = respSync_App.GetResponseStream()
len_App = respSync_App.ContentLength()

'Declare variable to track number of bytes downloaded ...
Dim cnt_App As Integer

'Iteratively download Kb by Kb ...
While total <= len_App
cnt_App = strm_App.Read(datBuffer, 0, 874)
If cnt_App <= 0 Then Exit While
fs_App.Write(datBuffer, 0, cnt_App)
total += cnt_App
End While

'Close the response/stream/filestream ...
respSync_App.Close()
strm_App.Close()
fs_App.Close()

'Release from memory ...
respSync_App = Nothing
strm_App = Nothing
fs_App = Nothing
Nov 21 '05 #1
3 3647
Hi,

Here is an example of how to download and unzip a file. It uses
the component one zip dll which was included with the vb.net resource kit.
Sorry the offer has ended for the resource kit so I cant post a link.

Dim request As WebRequest

Dim response As WebResponse

Dim reader As Stream

Dim writer As Stream

Dim data(1023) As Byte

Dim count As Integer

Dim total As Integer

Me.Show()

Me.Text = "Downloading file ....."

Application.DoEvents()

request =
WebRequest.Create("http://www.onteorasoftware.com/downloads/multigrids.zip")

response = request.GetResponse()

reader = response.GetResponseStream()

ProgressBar1.Maximum = CInt(response.ContentLength)

ProgressBar1.Value = 0

total = 0

writer = File.Create("mylocaldata.zip")

While True

count = reader.Read(data, 0, 1024)

If count <= 0 Then

Exit While

End If

writer.Write(data, 0, count)

total += 1024

If total < ProgressBar1.Maximum Then ProgressBar1.Value = total

Application.DoEvents()

End While

reader.Close()

writer.Close()

Dim mzip As New C1.C1Zip.C1ZipFile

'

mzip.Open("mylocaldata.zip")

Me.Text = "Extracting............."

Me.ProgressBar1.Value = 0

Me.ProgressBar1.Maximum = mzip.Entries.Count

Dim z As Integer = 0

For Each x As C1.C1Zip.C1ZipEntry In mzip.Entries

Dim fiZip As New System.IO.FileInfo(x.FileName)

Dim strDir As String = fiZip.DirectoryName.ToString

If Not Directory.Exists(strDir) Then Directory.CreateDirectory(strDir)

Trace.WriteLine(x.FileName)

z += 1

ProgressBar1.Value = z

mzip.Entries.Extract(x.FileName, fiZip.FullName)

Application.DoEvents()

Next x

Me.Text = "Done"

Ken

-----------------------

"Loane Sharp" <lo************@hotmail.com> wrote in message
news:Oa*************@TK2MSFTNGP12.phx.gbl...
Hi there

I use the FileStream object to download a zip file over the internet to my
local disk. The file downloads successfully, but when I attempt to unzip it,
I'm told that the file is in use by another process. This occurs even if I
release the object using fs.Close() and fs = Nothing.

Please help (my code is given below)

Best regards
Loane

'Create a new filestream to receive data ...
Dim fs_App As FileStream = New FileStream("C:\app.zip", FileMode.Create)

'Instantiate a new byte variable to receive data ...
datBuffer = New Byte(1023) {}

'Create a webrequest/response ...
Dim reqSync_App As WebRequest = WebRequest.Create("http://123.com/app.zip")
Dim respSync_App As WebResponse = reqSync_App.GetResponse()

'Retrieve file details (ie. file length) ...
Dim strm_App As Stream = respSync_App.GetResponseStream()
len_App = respSync_App.ContentLength()

'Declare variable to track number of bytes downloaded ...
Dim cnt_App As Integer

'Iteratively download Kb by Kb ...
While total <= len_App
cnt_App = strm_App.Read(datBuffer, 0, 874)
If cnt_App <= 0 Then Exit While
fs_App.Write(datBuffer, 0, cnt_App)
total += cnt_App
End While

'Close the response/stream/filestream ...
respSync_App.Close()
strm_App.Close()
fs_App.Close()

'Release from memory ...
respSync_App = Nothing
strm_App = Nothing
fs_App = Nothing

Nov 21 '05 #2
Hi Ken
Thanks for your reply.
I tried the code, which was very similar to my own, but I get the same
problem: "(file) in use by another process". P.S. I'm using nsoftware's
IPWorksZip rather than C1Zip, but that shouldn't make a difference, should
it?

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:er**************@TK2MSFTNGP10.phx.gbl...
Hi,

Here is an example of how to download and unzip a file. It
uses
the component one zip dll which was included with the vb.net resource kit.
Sorry the offer has ended for the resource kit so I cant post a link.

Dim request As WebRequest

Dim response As WebResponse

Dim reader As Stream

Dim writer As Stream

Dim data(1023) As Byte

Dim count As Integer

Dim total As Integer

Me.Show()

Me.Text = "Downloading file ....."

Application.DoEvents()

request =
WebRequest.Create("http://www.onteorasoftware.com/downloads/multigrids.zip")

response = request.GetResponse()

reader = response.GetResponseStream()

ProgressBar1.Maximum = CInt(response.ContentLength)

ProgressBar1.Value = 0

total = 0

writer = File.Create("mylocaldata.zip")

While True

count = reader.Read(data, 0, 1024)

If count <= 0 Then

Exit While

End If

writer.Write(data, 0, count)

total += 1024

If total < ProgressBar1.Maximum Then ProgressBar1.Value = total

Application.DoEvents()

End While

reader.Close()

writer.Close()

Dim mzip As New C1.C1Zip.C1ZipFile

'

mzip.Open("mylocaldata.zip")

Me.Text = "Extracting............."

Me.ProgressBar1.Value = 0

Me.ProgressBar1.Maximum = mzip.Entries.Count

Dim z As Integer = 0

For Each x As C1.C1Zip.C1ZipEntry In mzip.Entries

Dim fiZip As New System.IO.FileInfo(x.FileName)

Dim strDir As String = fiZip.DirectoryName.ToString

If Not Directory.Exists(strDir) Then Directory.CreateDirectory(strDir)

Trace.WriteLine(x.FileName)

z += 1

ProgressBar1.Value = z

mzip.Entries.Extract(x.FileName, fiZip.FullName)

Application.DoEvents()

Next x

Me.Text = "Done"

Ken

-----------------------

"Loane Sharp" <lo************@hotmail.com> wrote in message
news:Oa*************@TK2MSFTNGP12.phx.gbl...
Hi there

I use the FileStream object to download a zip file over the internet to my
local disk. The file downloads successfully, but when I attempt to unzip
it,
I'm told that the file is in use by another process. This occurs even if I
release the object using fs.Close() and fs = Nothing.

Please help (my code is given below)

Best regards
Loane

'Create a new filestream to receive data ...
Dim fs_App As FileStream = New FileStream("C:\app.zip", FileMode.Create)

'Instantiate a new byte variable to receive data ...
datBuffer = New Byte(1023) {}

'Create a webrequest/response ...
Dim reqSync_App As WebRequest =
WebRequest.Create("http://123.com/app.zip")
Dim respSync_App As WebResponse = reqSync_App.GetResponse()

'Retrieve file details (ie. file length) ...
Dim strm_App As Stream = respSync_App.GetResponseStream()
len_App = respSync_App.ContentLength()

'Declare variable to track number of bytes downloaded ...
Dim cnt_App As Integer

'Iteratively download Kb by Kb ...
While total <= len_App
cnt_App = strm_App.Read(datBuffer, 0, 874)
If cnt_App <= 0 Then Exit While
fs_App.Write(datBuffer, 0, cnt_App)
total += cnt_App
End While

'Close the response/stream/filestream ...
respSync_App.Close()
strm_App.Close()
fs_App.Close()

'Release from memory ...
respSync_App = Nothing
strm_App = Nothing
fs_App = Nothing

Nov 21 '05 #3
Hi,

This works with the ipworkszip ver 6.0

Dim request As WebRequest

Dim response As WebResponse

Dim reader As Stream

Dim writer As Stream

Dim data(1023) As Byte

Dim count As Integer

Dim total As Integer

Me.Show()

Me.Text = "Downloading file ....."

Application.DoEvents()

request =
WebRequest.Create("http://www.onteorasoftware.com/downloads/multigrids.zip")

response = request.GetResponse()

reader = response.GetResponseStream()

ProgressBar1.Maximum = CInt(response.ContentLength)

ProgressBar1.Value = 0

total = 0

writer = File.Create("mylocaldata.zip")

While True

count = reader.Read(data, 0, 1024)

If count <= 0 Then

Exit While

End If

writer.Write(data, 0, count)

total += 1024

If total < ProgressBar1.Maximum Then ProgressBar1.Value = total

Application.DoEvents()

End While

reader.Close()

writer.Close()

Application.DoEvents()

Me.Text = "Extracting............."

Application.DoEvents()

zip1.ArchiveFile = "mylocaldata.zip"

zip1.ExtractToPath = "C:\Zip Test"

'Zip1.Password = "test" 'if applicable

zip1.ExtractAll()

Me.Text = "Done"

Ken

------------------------------

"Loane Sharp" <lo************@hotmail.com> wrote in message
news:uB**************@TK2MSFTNGP15.phx.gbl...
Hi Ken
Thanks for your reply.
I tried the code, which was very similar to my own, but I get the same
problem: "(file) in use by another process". P.S. I'm using nsoftware's
IPWorksZip rather than C1Zip, but that shouldn't make a difference, should
it?

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:er**************@TK2MSFTNGP10.phx.gbl...
Hi,

Here is an example of how to download and unzip a file. It
uses
the component one zip dll which was included with the vb.net resource kit.
Sorry the offer has ended for the resource kit so I cant post a link.

Dim request As WebRequest

Dim response As WebResponse

Dim reader As Stream

Dim writer As Stream

Dim data(1023) As Byte

Dim count As Integer

Dim total As Integer

Me.Show()

Me.Text = "Downloading file ....."

Application.DoEvents()

request =
WebRequest.Create("http://www.onteorasoftware.com/downloads/multigrids.zip")

response = request.GetResponse()

reader = response.GetResponseStream()

ProgressBar1.Maximum = CInt(response.ContentLength)

ProgressBar1.Value = 0

total = 0

writer = File.Create("mylocaldata.zip")

While True

count = reader.Read(data, 0, 1024)

If count <= 0 Then

Exit While

End If

writer.Write(data, 0, count)

total += 1024

If total < ProgressBar1.Maximum Then ProgressBar1.Value = total

Application.DoEvents()

End While

reader.Close()

writer.Close()

Dim mzip As New C1.C1Zip.C1ZipFile

'

mzip.Open("mylocaldata.zip")

Me.Text = "Extracting............."

Me.ProgressBar1.Value = 0

Me.ProgressBar1.Maximum = mzip.Entries.Count

Dim z As Integer = 0

For Each x As C1.C1Zip.C1ZipEntry In mzip.Entries

Dim fiZip As New System.IO.FileInfo(x.FileName)

Dim strDir As String = fiZip.DirectoryName.ToString

If Not Directory.Exists(strDir) Then Directory.CreateDirectory(strDir)

Trace.WriteLine(x.FileName)

z += 1

ProgressBar1.Value = z

mzip.Entries.Extract(x.FileName, fiZip.FullName)

Application.DoEvents()

Next x

Me.Text = "Done"

Ken

-----------------------

"Loane Sharp" <lo************@hotmail.com> wrote in message
news:Oa*************@TK2MSFTNGP12.phx.gbl...
Hi there

I use the FileStream object to download a zip file over the internet to my
local disk. The file downloads successfully, but when I attempt to unzip
it,
I'm told that the file is in use by another process. This occurs even if I
release the object using fs.Close() and fs = Nothing.

Please help (my code is given below)

Best regards
Loane

'Create a new filestream to receive data ...
Dim fs_App As FileStream = New FileStream("C:\app.zip", FileMode.Create)

'Instantiate a new byte variable to receive data ...
datBuffer = New Byte(1023) {}

'Create a webrequest/response ...
Dim reqSync_App As WebRequest =
WebRequest.Create("http://123.com/app.zip")
Dim respSync_App As WebResponse = reqSync_App.GetResponse()

'Retrieve file details (ie. file length) ...
Dim strm_App As Stream = respSync_App.GetResponseStream()
len_App = respSync_App.ContentLength()

'Declare variable to track number of bytes downloaded ...
Dim cnt_App As Integer

'Iteratively download Kb by Kb ...
While total <= len_App
cnt_App = strm_App.Read(datBuffer, 0, 874)
If cnt_App <= 0 Then Exit While
fs_App.Write(datBuffer, 0, cnt_App)
total += cnt_App
End While

'Close the response/stream/filestream ...
respSync_App.Close()
strm_App.Close()
fs_App.Close()

'Release from memory ...
respSync_App = Nothing
strm_App = Nothing
fs_App = Nothing


Nov 21 '05 #4

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

Similar topics

0
by: Eric Brasher | last post by:
I am trying to work with the new sdk 3.0 from quickbooks which allows subscriptions to events in the quickbooks app. One problem I am having is creating an activex exe using vb.net. The...
4
by: Earth Worm Jim | last post by:
I am using VS.Net 2003 on Windows 2003 Server (standard edition) and I am getting "The process cannot access the file because it is being used by another process" on DLL's in a VS.Net solution. ...
3
by: kris.dorey | last post by:
Hi, Ive got the following code which seems ok but when the user runs the function for a second time I get an error message stating that the mdb is in use by another process. There is still an...
3
by: Bob | last post by:
I've been repeatedly annoyed by situations where a process has failed or otherwise something has gone wrong (not from any of my own apps) where I cannot move, rename, or delete a file because...
2
by: Goran Djuranovic | last post by:
Hi all, I was getting this error when trying to move files on a FileSystemWatcher notification (with in a Windows Service). To fix this, I implemented a FileWaiter class to wait for the file to be...
7
by: Robinson | last post by:
Hi, I was just playing around with my log files and tried to open a log file programmatically that was considered "in use" (I got an in-use exception). The file is being used by my debug writer...
1
by: othgwayne | last post by:
I am writing in .NET VB 2003 I have an app that uses a file system watcher looking for a file to fall into this directory. When the file falls, it is opened, processed, closed and deleted. Then...
1
by: eran otzar | last post by:
I've got a problem wich cant manage to overcome although it might seem fairly simple. I've got a chat program, in wich i want to enable users to change user pics at runtime. There's a picture box...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.