L
Loane Sharp
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
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