473,573 Members | 2,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Crea te("http://123.com/app.zip")
Dim respSync_App As WebResponse = reqSync_App.Get Response()

'Retrieve file details (ie. file length) ...
Dim strm_App As Stream = respSync_App.Ge tResponseStream ()
len_App = respSync_App.Co ntentLength()

'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(d atBuffer, 0, 874)
If cnt_App <= 0 Then Exit While
fs_App.Write(da tBuffer, 0, cnt_App)
total += cnt_App
End While

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

'Release from memory ...
respSync_App = Nothing
strm_App = Nothing
fs_App = Nothing
Nov 21 '05 #1
3 3675
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 = "Downloadin g file ....."

Application.DoE vents()

request =
WebRequest.Crea te("http://www.onteorasoft ware.com/downloads/multigrids.zip" )

response = request.GetResp onse()

reader = response.GetRes ponseStream()

ProgressBar1.Ma ximum = CInt(response.C ontentLength)

ProgressBar1.Va lue = 0

total = 0

writer = File.Create("my localdata.zip")

While True

count = reader.Read(dat a, 0, 1024)

If count <= 0 Then

Exit While

End If

writer.Write(da ta, 0, count)

total += 1024

If total < ProgressBar1.Ma ximum Then ProgressBar1.Va lue = total

Application.DoE vents()

End While

reader.Close()

writer.Close()

Dim mzip As New C1.C1Zip.C1ZipF ile

'

mzip.Open("mylo caldata.zip")

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

Me.ProgressBar1 .Value = 0

Me.ProgressBar1 .Maximum = mzip.Entries.Co unt

Dim z As Integer = 0

For Each x As C1.C1Zip.C1ZipE ntry In mzip.Entries

Dim fiZip As New System.IO.FileI nfo(x.FileName)

Dim strDir As String = fiZip.Directory Name.ToString

If Not Directory.Exist s(strDir) Then Directory.Creat eDirectory(strD ir)

Trace.WriteLine (x.FileName)

z += 1

ProgressBar1.Va lue = z

mzip.Entries.Ex tract(x.FileNam e, fiZip.FullName)

Application.DoE vents()

Next x

Me.Text = "Done"

Ken

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

"Loane Sharp" <lo************ @hotmail.com> wrote in message
news:Oa******** *****@TK2MSFTNG P12.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.Crea te("http://123.com/app.zip")
Dim respSync_App As WebResponse = reqSync_App.Get Response()

'Retrieve file details (ie. file length) ...
Dim strm_App As Stream = respSync_App.Ge tResponseStream ()
len_App = respSync_App.Co ntentLength()

'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(d atBuffer, 0, 874)
If cnt_App <= 0 Then Exit While
fs_App.Write(da tBuffer, 0, cnt_App)
total += cnt_App
End While

'Close the response/stream/filestream ...
respSync_App.Cl ose()
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***@bellsout h.net> wrote in message
news:er******** ******@TK2MSFTN GP10.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 = "Downloadin g file ....."

Application.DoE vents()

request =
WebRequest.Crea te("http://www.onteorasoft ware.com/downloads/multigrids.zip" )

response = request.GetResp onse()

reader = response.GetRes ponseStream()

ProgressBar1.Ma ximum = CInt(response.C ontentLength)

ProgressBar1.Va lue = 0

total = 0

writer = File.Create("my localdata.zip")

While True

count = reader.Read(dat a, 0, 1024)

If count <= 0 Then

Exit While

End If

writer.Write(da ta, 0, count)

total += 1024

If total < ProgressBar1.Ma ximum Then ProgressBar1.Va lue = total

Application.DoE vents()

End While

reader.Close()

writer.Close()

Dim mzip As New C1.C1Zip.C1ZipF ile

'

mzip.Open("mylo caldata.zip")

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

Me.ProgressBar1 .Value = 0

Me.ProgressBar1 .Maximum = mzip.Entries.Co unt

Dim z As Integer = 0

For Each x As C1.C1Zip.C1ZipE ntry In mzip.Entries

Dim fiZip As New System.IO.FileI nfo(x.FileName)

Dim strDir As String = fiZip.Directory Name.ToString

If Not Directory.Exist s(strDir) Then Directory.Creat eDirectory(strD ir)

Trace.WriteLine (x.FileName)

z += 1

ProgressBar1.Va lue = z

mzip.Entries.Ex tract(x.FileNam e, fiZip.FullName)

Application.DoE vents()

Next x

Me.Text = "Done"

Ken

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

"Loane Sharp" <lo************ @hotmail.com> wrote in message
news:Oa******** *****@TK2MSFTNG P12.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.Crea te("http://123.com/app.zip")
Dim respSync_App As WebResponse = reqSync_App.Get Response()

'Retrieve file details (ie. file length) ...
Dim strm_App As Stream = respSync_App.Ge tResponseStream ()
len_App = respSync_App.Co ntentLength()

'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(d atBuffer, 0, 874)
If cnt_App <= 0 Then Exit While
fs_App.Write(da tBuffer, 0, cnt_App)
total += cnt_App
End While

'Close the response/stream/filestream ...
respSync_App.Cl ose()
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 = "Downloadin g file ....."

Application.DoE vents()

request =
WebRequest.Crea te("http://www.onteorasoft ware.com/downloads/multigrids.zip" )

response = request.GetResp onse()

reader = response.GetRes ponseStream()

ProgressBar1.Ma ximum = CInt(response.C ontentLength)

ProgressBar1.Va lue = 0

total = 0

writer = File.Create("my localdata.zip")

While True

count = reader.Read(dat a, 0, 1024)

If count <= 0 Then

Exit While

End If

writer.Write(da ta, 0, count)

total += 1024

If total < ProgressBar1.Ma ximum Then ProgressBar1.Va lue = total

Application.DoE vents()

End While

reader.Close()

writer.Close()

Application.DoE vents()

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

Application.DoE vents()

zip1.ArchiveFil e = "mylocaldata.zi p"

zip1.ExtractToP ath = "C:\Zip Test"

'Zip1.Password = "test" 'if applicable

zip1.ExtractAll ()

Me.Text = "Done"

Ken

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

"Loane Sharp" <lo************ @hotmail.com> wrote in message
news:uB******** ******@TK2MSFTN GP15.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***@bellsout h.net> wrote in message
news:er******** ******@TK2MSFTN GP10.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 = "Downloadin g file ....."

Application.DoE vents()

request =
WebRequest.Crea te("http://www.onteorasoft ware.com/downloads/multigrids.zip" )

response = request.GetResp onse()

reader = response.GetRes ponseStream()

ProgressBar1.Ma ximum = CInt(response.C ontentLength)

ProgressBar1.Va lue = 0

total = 0

writer = File.Create("my localdata.zip")

While True

count = reader.Read(dat a, 0, 1024)

If count <= 0 Then

Exit While

End If

writer.Write(da ta, 0, count)

total += 1024

If total < ProgressBar1.Ma ximum Then ProgressBar1.Va lue = total

Application.DoE vents()

End While

reader.Close()

writer.Close()

Dim mzip As New C1.C1Zip.C1ZipF ile

'

mzip.Open("mylo caldata.zip")

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

Me.ProgressBar1 .Value = 0

Me.ProgressBar1 .Maximum = mzip.Entries.Co unt

Dim z As Integer = 0

For Each x As C1.C1Zip.C1ZipE ntry In mzip.Entries

Dim fiZip As New System.IO.FileI nfo(x.FileName)

Dim strDir As String = fiZip.Directory Name.ToString

If Not Directory.Exist s(strDir) Then Directory.Creat eDirectory(strD ir)

Trace.WriteLine (x.FileName)

z += 1

ProgressBar1.Va lue = z

mzip.Entries.Ex tract(x.FileNam e, fiZip.FullName)

Application.DoE vents()

Next x

Me.Text = "Done"

Ken

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

"Loane Sharp" <lo************ @hotmail.com> wrote in message
news:Oa******** *****@TK2MSFTNG P12.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.Crea te("http://123.com/app.zip")
Dim respSync_App As WebResponse = reqSync_App.Get Response()

'Retrieve file details (ie. file length) ...
Dim strm_App As Stream = respSync_App.Ge tResponseStream ()
len_App = respSync_App.Co ntentLength()

'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(d atBuffer, 0, 874)
If cnt_App <= 0 Then Exit While
fs_App.Write(da tBuffer, 0, cnt_App)
total += cnt_App
End While

'Close the response/stream/filestream ...
respSync_App.Cl ose()
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
1346
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 subscription process states that the com object used to recieve events from qb has to run out of process. How do I create an "Out of Process" compatible...
4
13234
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. I have made sure all the dependancies and the build order is correct but the actually instance of VS.Net (devenv.exe) is LOCKING THE DAM DLL'S IT IS...
3
2985
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 ldb for the life of the application even after calling oldebconnection.close and gc.collect. Any ideas?
3
1441
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 Windows thinks it's "being used by another process". There are no processes evident using the file(s) or folder(s), so in order to clean them up I need...
2
5294
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 ReadWrite accessible, and that worked fine on two PCs (Windows XP Pro SP2 & Windows XP Pro). But when I tried this on my third PC that had Windows...
7
2186
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 and I wanted to read lines from the file on one of my forms. It's a simple text file by the way. Now obviously the exception I get from the code...
1
1345
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 it goes back to the watcher looking for the next file to drop. All of this happens as expected without a hitch. UNTIL the second file falls. the...
1
26273
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 winch is set to an image with the name of a certain peer for example : "C:\\FriendLy\\Users\\eran\\Pictures\\eva.jpg" Now what i need is to replace...
0
7771
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7686
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7771
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8060
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6406
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3730
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1296
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1036
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.