Hello, everyone! I'm using the WebClient class' OpenWriteAsync function, and I'm having a little trouble with it. I want it to write some information to a .txt file I have uploaded on my FTP. I made it display a message after it has completed doing so, and the message does indeed pop up. However, I've checked my .txt file numerous times, and it hasn't actually been edited. I'm wondering if someone could please help me out with this. Here's some of my code:
Am I doing anything wrong or missing something? Thanks in advance!Code:Dim otherclient As New WebClient() AddHandler otherclient.OpenWriteCompleted, AddressOf WriteCompleted otherclient.OpenWriteAsync(New Uri(URL)) Private Sub WriteCompleted(ByVal sender As System.Object, ByVal e As OpenWriteCompletedEventArgs) Try If e.Error Is Nothing And e.Cancelled = False Then Dim FileStream As Stream = e.Result Dim Bytes() As Byte = System.Text.Encoding.UTF8.GetBytes(txtTest.Text & vbNewLine) FileStream.Write(Bytes, 0, Bytes.Length) FileStream.Flush() FileStream.Close() MsgBox("Complete!") Else MsgBox(e.Error) Exit Sub End If Catch ex As Exception MsgBox(ex.Message) Exit Sub End Try End Sub




Reply With Quote
