473,700 Members | 2,510 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 3684
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
1353
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 solution in vb.net?
4
13244
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 TRYING TO BUILD. ????? I have used Process Explorer from sysinternals.com to confirm this.
3
2992
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
1444
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 to log out of Windows (XP) and log back in. Out of curiosity, would it be possible to use DotNet...
2
5297
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 XP Pro SP1 installed, it would not work. The file that was copied to folder was never accessible,...
7
2192
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 trying to open the file for reading looks like this: The process cannot access the file...
1
1347
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 first step is: Dim fsStream As New FileStream(sFullHS1Path, FileMode.Open, FileAccess.Read) This...
1
26323
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 this picture and override it. The first thing i do is copy it to a new location (becuase i dont...
0
9081
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8975
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8931
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7819
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5904
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4408
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3097
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2032
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.