473,548 Members | 2,633 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 3670
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
1341
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
13232
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
2984
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
1439
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
2185
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
1343
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
26261
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
7438
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...
0
7707
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7951
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...
0
7803
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...
1
5362
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
5082
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...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1926
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
0
751
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.