Q:

Insert string to  tag

I'm developing a client that connects to my server, and get access to download and upload files, and i seem to be stuck at uploading files. Here is my code on my VB.NET client:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'Upload button
    WebBrowser1.Visible = True

    'Style OpenFileDialog1
    OpenFileDialog1.Title = "Select file to upload"
    OpenFileDialog1.InitialDirectory = System.Environment.SpecialFolder.Desktop

    OpenFileDialog1.ShowDialog()

End Sub

Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk

    uploadFile = OpenFileDialog1.FileName.ToString()

    If uploadFile = Nothing Then
        MessageBox.Show("You just selected nothing.", "Information")
    Else
        WebBrowser1.Document.GetElementById("fileselect").SetAttribute("value", uploadFile)
        WebBrowser1.Document.GetElementById("submit").InvokeMember("click")
    End If

End Sub

And here is the HTML code:
<input type="file" id="fileselect" name="fileselect[]" multiple="multiple" />

<button type="submit" id="submit" class="uploadButton">Upload Files</button>

Also how do i make so that i can select multiple files? Via the web version you can select multiple files and it workes not not here?

A:

So, as mentioned in the comments, input elements of type file do not allow for external modification, all interaction with them is done through the browser and is based on direct user interaction.
However, you could create an upload class that process the multiple file upload to your server, by creating a HttpWebRequest, which sends the data to the form. Provided there is no authentication, it can be done in the following way.
An interface that allows for some elementary actions for post data items
Public Interface IPostItem
    ReadOnly Property Title As String
    Property ElementName As String
    Function GetPostData(inputNameElement As String) As String
End Interface

Some way to define the mime type of the file being sent
Public NotInheritable Class MimeTypeHandler
    Private Shared ReadOnly images As String() = {"jpg", "gif", "bmp", "png", "jpeg"}

    Public Shared Function GetMimeType(filename As String) As String
        Dim extension As String = Path.GetExtension(filename).Replace(".", "")
        If (images.Contains(extension)) Then
            Return "image/" + extension
        End If
        Return "application/" + extension
    End Function
End Class

Implement the IPostItem with an implementation that can post the file
Public Class FileQueueItem
    Implements IPostItem

    Public Property FileName As String

    Public Property ElementName As String Implements IPostItem.ElementName

    Public Function GetData() As Byte()
        Dim result As Byte() = Nothing
        Dim lengthRead As Integer = 0
        Using stream As New FileStream(FileName, FileMode.Open, FileAccess.Read)
            ReDim result(stream.Length)
            lengthRead = stream.Read(result, 0, stream.Length)
        End Using
        Return result
    End Function

    Public ReadOnly Property ShortName As String Implements IPostItem.Title
        Get
            Return FileName.Substring(FileName.LastIndexOf("\") + 1)
        End Get
    End Property

    Public ReadOnly Property MimeType As String
        Get
            Return MimeTypeHandler.GetMimeType(FileName)
        End Get
    End Property

    Public Function GetPostData(inputNameElement As String) As String Implements IPostItem.GetPostData
        Dim message As String = String.Empty
        message += String.Format("Content-Disposition: form-data; name=""{0}""; filename=""{1}""{3}Content-Type: {2}{3}Content-Transfer-Encoding: base64{3}{3}", inputNameElement, ShortName, MimeType, Environment.NewLine)
        message += Convert.ToBase64String(GetData())
        Return message
    End Function

    Public Sub New(filename As String, elementName As String)
        Me.FileName = filename
        Me.ElementName = elementName
    End Sub
End Class

Have a small controller class that runs the upload sequence using the BackgroundWorker class, it sends the files per 5 (can be set, is default value).
It requires a FormUrl, to say where the form is that is being posted to, in my case, i was running it on my localhost, so that you would see in the form code
Public Class FileUploader
    Inherits BackgroundWorker
    Private ReadOnly _listQueue As IList(Of IPostItem) = New List(Of IPostItem)

    Public Property FormUrl As String

    Public ReadOnly Property ListQueue As IList(Of IPostItem)
        Get
            Return _listQueue
        End Get
    End Property

    Public Property MaxPerQueue As Integer

    Protected Function HandleResponse(request As HttpWebRequest) As Boolean
        Dim success As Boolean = False
        Try
            Using response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
                success = response.StatusCode <> HttpStatusCode.OK
            End Using
        Catch ex As WebException
            If ex.Response IsNot Nothing Then
                ex.Response.Close()
            End If
        End Try
        Return success
    End Function

    Protected Sub Run(sender As Object, e As DoWorkEventArgs)
        If ListQueue.Count = 0 Then
            ' nothing to upload
            Return
        End If
        ' create the boundary string, used to split between the separate attachments
        Dim boundary As String = String.Format("--------------------------{0}", DateTime.Now.Ticks)
        Dim count As Integer = 0
        Dim totalFiles As Integer = ListQueue.Count

        Do
            ' create the request
            Dim request As HttpWebRequest = CType(WebRequest.Create(Me.FormUrl), HttpWebRequest)
            Dim fullPostMessage As String = String.Empty
            request.AllowAutoRedirect = True
            request.KeepAlive = True
            request.Referer = Me.FormUrl
            ''// say that it has to post data
            request.Method = WebRequestMethods.Http.Post
            ''// same style like a form
            request.ContentType = "multipart/form-data;boundary=" + boundary
            count = 0
            Dim queueItem As IPostItem
            While count < MaxPerQueue AndAlso ListQueue.Count > 0
                ''// get the item in the queue
                queueItem = ListQueue(0)
                ''// report potential changes to gui
                Report(queueItem.Title, count, totalFiles)
                Dim postAsString As String = queueItem.GetPostData(queueItem.ElementName)
                fullPostMessage &= String.Format("--{0}{1}{2}{1}", boundary, Environment.NewLine, postAsString)
                ''// remove the item from the queue
                ListQueue.RemoveAt(0)
                count += 1
            End While
            fullPostMessage &= "--" & boundary & "--"
            Dim postData As Byte() = System.Text.Encoding.ASCII.GetBytes(fullPostMessage)
            ''// write data to the requestStream (post data)
            request.ContentLength = postData.Length
            Dim requestStream As Stream = request.GetRequestStream()
            requestStream.Write(postData, 0, postData.Length)
            requestStream.Close()
            ''// handle the response
            HandleResponse(request)
            requestStream.Dispose()
        Loop While ListQueue.Count > 0
        ListQueue.Clear()
        Report("(Idle)", 0, 100)
    End Sub

    Protected Sub Report(filename As String, fileIndex As Integer, maxFiles As Integer)
        Dim percentage As Integer = (fileIndex * 100) / maxFiles
        ReportProgress(percentage, filename)
    End Sub

    Public Sub New()
        Me.WorkerReportsProgress = True
        AddHandler Me.DoWork, AddressOf Run
        MaxPerQueue = 5
    End Sub
End Class

Then you could create your form like this:

And then add the FileUploader class as a private member, so you can get notified when it has completed the upload stream, add the eventhandlers to get notified on the changes
Imports System.ComponentModel
Imports System.Net
Imports System.IO

Public Class Form1
    Private fileUploadHandler As New FileUploader()

    Private Sub btnUploadFiles_Click(sender As Object, e As EventArgs) Handles btnUploadFiles.Click

        fileUploadHandler.FormUrl = "http://localhost:5555/Default.aspx"
        Using openDialog As New OpenFileDialog
            openDialog.Multiselect = True
            openDialog.Title = "Select files to upload to the server"
            If openDialog.ShowDialog() Then
                ' all files are selected
                For Each fileName As String In openDialog.FileNames
                    Dim qItem As IPostItem = New FileQueueItem(fileName, "fileInfo[]")
                    fileUploadHandler.ListQueue.Add(qItem)
                Next
                btnUploadFiles.Enabled = False
                fileUploadHandler.RunWorkerAsync()
            End If
        End Using
    End Sub

    Private Sub OnUploadCompleted(sender As Object, e As RunWorkerCompletedEventArgs)
        btnUploadFiles.Enabled = True
    End Sub

    Private Sub OnReportProgress(sender As Object, e As ProgressChangedEventArgs)
        pbUploadProgress.Value = e.ProgressPercentage
        lblUploadProgress.Text = e.UserState
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        AddHandler fileUploadHandler.RunWorkerCompleted, AddressOf OnUploadCompleted
        AddHandler fileUploadHandler.ProgressChanged, AddressOf OnReportProgress
    End Sub
End Class

The files get then uploaded as soon as you click the Open button in the OpenFileDialog.
As to your second question, to allow for more than 1 file selected, you have to set the OpenFileDialog.Multiselect = True flag

