A1VBCode Forums

VB Console application


http://www.a1vbcode.com/vbforums/Topic31673.aspx

By SDK - 10/15/2012

UploadValuesAsync Method does not working for Console Application Any idea ???? Sad
By SDK - 10/15/2012

Sample Code



Imports System.Net

Imports System.Xml

Imports System.IO

Imports System.Text

Imports System.Data.OleDb

'Imports ADODB

Imports System.Net.WebProxy

Imports System.Net.HttpWebRequest

Module Module1

Sub Main()

Console.WriteLine("Calling...")

Try

For x As Integer = 0 To 3

import("\temp\xml1.txt")

Next

Catch ex As Exception

Console.WriteLine(ex.Message)

End Try

Console.WriteLine("Completed")

End Sub



Private Sub import(ByVal filename As String)

Try

Dim objReader As New StreamReader(filename)

Dim sLine As String = ""

Dim arrText As New ArrayList()

Do

sLine = objReader.ReadLine()

If Not sLine Is Nothing Then

arrText.Add(sLine)

End If

Loop Until sLine Is Nothing

objReader.Close()

Dim a As String = ""

For Each sLine In arrText

a = a + sLine

Next

Dim creatorApiUrl As String = ""

Dim uri1 As Uri = New Uri(creatorApiUrl)

Dim creator_client As WebClient = New WebClient

Dim myNameValueCollection As New System.Collections.Specialized.NameValueCollection

myNameValueCollection.Add("XMLString", a)

Dim handler As UploadValuesCompletedEventHandler = New UploadValuesCompletedEventHandler(AddressOf Completed)

AddHandler creator_client.UploadValuesCompleted, handler



creator_client.Headers.Add("CharSet", "UTF-8")

creator_client.UploadValuesAsync(uri1, myNameValueCollection)

Catch ex As Exception

Console.WriteLine(ex.Message)

End Try

End Sub

Private Sub Completed(ByVal sender As Object, ByVal e As UploadValuesCompletedEventArgs)

Console.WriteLine("Success")

End Sub

End Module





Above code using in console application. It's working fine in Windows Form Appliaction.