File upload from Pocket PC to web page, code examples

D

Dan Hagerman

I've been struggling with uploading a file from a Pocket PC (.Net Compact
Framework v2) app to a web page (ASP.Net 2.0). I can successfully upload to
my page from an HTML page, but not from the app. I always get the "No File
received by web server" message (see code). I appreciate any tips! Thanks.

file.aspx.vb code:
----------------------------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If Request.Files.Count = 0 Then
Response.Write("No file received by web server.")
Exit Sub
End If

Dim filepath As String = Server.MapPath("~/images")

Dim userPostedFile As HttpPostedFile = Request.Files(0)

userPostedFile.SaveAs(filepath & "\" &
System.IO.Path.GetFileName(userPostedFile.FileName))

Response.Write("Success" & vbCrLf)

End Sub
----------------------------------------------------------


Pocket PC code:
----------------------------------------------------------
Private Function SendFile(ByVal ImageFile As String) As Boolean

'send to web site
Dim UploadURL As String = tURL & "file.aspx"

Dim WebReq As HttpWebRequest =
CType(WebRequest.Create(UploadURL), HttpWebRequest)
WebReq.Method = "POST"
WebReq.AllowWriteStreamBuffering = True

'retrieve request stream
Dim reqStream As Stream = WebReq.GetRequestStream()

'open the local file
Dim rdr As FileStream = New FileStream(ImageFile, FileMode.Open)

'allocate byte buffer to hold file contents
Dim inData(4096) As Byte

'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

rdr.Close()
rdr = Nothing
reqStream.Close()
reqStream = Nothing

Dim WebResp As HttpWebResponse = CType(WebReq.GetResponse(),
HttpWebResponse)

'process response

End Function
----------------------------------------------------------
 
B

Bob Barrows

Dan said:
I've been struggling with uploading a file from a Pocket PC (.Net
Compact Framework v2) app to a web page (ASP.Net 2.0).

There was no way for you to know it (except maybe by browsing through
some of the previous questions before posting yours - always a
recommended practice), but this is a classic (COM-based) asp newsgroup.
ASP.Net is a different technology from classic ASP. While you may be
lucky enough to find a dotnet-savvy person here who can answer your
question, you can eliminate the luck factor by posting your question to
a newsgroup where the dotnet-savvy people hang out. I suggest

microsoft.public.dotnet.framework.aspnet.

There are also forums at www.asp.net where you can find a lot of people
to help you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,821
Messages
2,569,749
Members
45,734
Latest member
DarrellDur

Latest Threads

Top