We help IT Professionals succeed at work.
Get Started

Convert C# to VB

tonelm54 asked
Last Modified: 2012-05-09
Ive been trying to convert some c# code from 'http://www.c-sharpcorner.com/UploadFile/nipuntomar/FileUploadsilverlight03182009030537AM/FileUploadsilverlight.aspx' however having issues with the section:-
            c.OpenWriteCompleted += (sender, e) =>
                PushData(data, e.Result);

My latest attempt was to run it through a code conversion tool at http://www.developerfusion.com/tools/convert/csharp-to-vb/, but still produces errors most of which I fixed, but still have the bit above.

I have tried using the raiseevent code, but it just tells me end of statment expected :-(

Any ideas?

Imports System.IO
Imports System
Imports System.Net

Partial Public Class MainPage
    Inherits UserControl

    Public Sub New()
    End Sub
    Private Sub UploadFile(ByVal fileName As String, ByVal data As Stream)
        Dim ub As New UriBuilder("http://localhost:3840/receiver.ashx")
        ub.Query = String.Format("filename={0}", fileName)
        Dim c As New WebClient
 	c.OpenWriteCompleted += Function(sender, e) Do
        PushData(data, e.Result)
    End Sub
End Sub

    Private Sub PushData(ByVal input As Stream, ByVal output As Stream)
        Dim buffer As Byte() = New Byte(4095) {}
        Dim bytesRead As Integer

        While (InlineAssignHelper(bytesRead, input.Read(buffer, 0, buffer.Length))) <> 0
            output.Write(buffer, 0, bytesRead)
        End While
    End Sub
End Class

Open in new window

Watch Question
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
This problem has been solved!
Unlock 1 Answer and 12 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE