Hi, I found myself a difficulty on creating a image uploader to my database. This is because in .NET CF, I cant find File Upload control. Is there any other options and how should I do it?

I know there is a OpenFileControl but there is a problem on saving it / previewing it on a picture box.

Thanks for any help.

7 Years
Discussion Span
Last Post by samuel_1991

>Is there any other options and how should I do it?

You need to use WebService.

Hi, yes I am using Web Service, Access 2007 accdb as my database. (The retrieve records such as Login from other components works fine)

So, do you mean the upload code are suppose to be on WebService, and the openfile dialog will make use of the web service's upload class?


However, if I use Webservice, I will get an error of "System.IO.DirectoryNotFoundException"

If I chose to implement this upload function right below all subs (Within the PDA's class), I will get a 405 error.

The code is as follows:

Public Sub UploadFileBinary(ByVal localFile As String, ByVal uploadUrl As String)
            Dim req As HttpWebRequest = DirectCast(WebRequest.Create(uploadUrl), HttpWebRequest)

            req.Method = "PUT"
            req.AllowWriteStreamBuffering = True

            ' Retrieve request stream 
            Dim reqStream As Stream = req.GetRequestStream()

            ' Open the local file
            Dim rdr As New FileStream(localFile, FileMode.Open)

            ' Allocate byte buffer to hold file contents
            Dim inData As Byte() = New Byte(4095) {}

            ' loop through the local file reading each data block
            '  and writing to the request stream buffer
            Dim bytesRead As Integer = rdr.Read(inData, 0, inData.Length)
            While bytesRead > 0
                reqStream.Write(inData, 0, bytesRead)
                bytesRead = rdr.Read(inData, 0, inData.Length)
            End While


        Catch ex As Exception
            MsgBox("Unable to connect error:" & Chr(10) & ex.Message)
        End Try
    End Sub

To call the above subroutine, I used the following code on Button click event (Submit)

'Upload the image
                Dim UploadURL As String = "http://smlj/OCC/Images" + Path.GetFileName(txtImg.Text)
                UploadFileBinary(txtImg.Text, UploadURL)
'Where UploadURL is a string contains my computer name and the actual directory and txtImg.Text is the read-only textbox that shows the selected image to be uploaded.

PS: If I typed "http://smlj/OCC/Images" without quotes in the browser, I can see the directory listing. Neither is there a prompt of administrator rights when I tried to copy a file to that directory.

I also did

Imports System.IO

on the first line as well.

Edited by samuel_1991: n/a



I forgot to mention that I had used

Imports System.Net

as well.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.