Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.
Private Sub btnDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownload.Click fdb.SelectedPath = Application.StartupPath fdb.ShowDialog() Dim tempSaveDir = fdb.SelectedPath Try Dim outputStream As FileStream = New FileStream(fdb.SelectedPath + "\\" + lbFiles.SelectedItem, FileMode.OpenOrCreate) Dim clsRequest As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create(tempurl & "/" & lbFiles.SelectedItem), System.Net.FtpWebRequest) clsRequest.Credentials = New System.Net.NetworkCredential(Form1.tbUser.Text, Form1.tbPass.Text) clsRequest.Method = System.Net.WebRequestMethods.Ftp.DownloadFile Dim response As FtpWebResponse = clsRequest.GetResponse Dim ftpStream As Stream = response.GetResponseStream() Dim cl As String = response.ContentLength MsgBox(cl) Dim bufferSize As Integer = 1024 Dim readCount As Integer Dim buffer(bufferSize) As Byte Dim tempCount = 0 ProgressBar.Value = 0 While True readCount = ftpStream.Read(buffer, 0, bufferSize) If readCount > 0 Then outputStream.Write(buffer, 0, readCount) 'ProgressBar.Value = (tempCount / cl) * 100 End If 'MsgBox(outputstre) End While ftpStream.Flush() outputStream.Flush() ftpStream.Dispose() outputStream.Dispose() response.Close() Catch ui As UriFormatException MsgBox("ui " + ui.Message) Catch io As IOException MsgBox("IO " + io.Message) Catch ex As Exception MsgBox("EX " + ex.Message) End Try End Sub ERROR I receive when trying to download I get about 75% of the way thru the download - EX Cannot access adisposed object. Object name: 'system.net.sockets.networkstream'. Then it just stops and aborts the download all this doesnt make sense because im not disposing any object untill after the read AND I commented the code out and still doenst work.
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.