File upload from Pocket PC to web page, code examples

Discussion in 'ASP General' started by Dan Hagerman, Dec 23, 2008.

  1. Dan Hagerman

    Dan Hagerman Guest

    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
    ----------------------------------------------------------
     
    Dan Hagerman, Dec 23, 2008
    #1
    1. Advertising

  2. Dan Hagerman

    Bob Barrows Guest

    Dan Hagerman wrote:
    > 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.
    --
    HTH,
    Bob Barrows
     
    Bob Barrows, Dec 23, 2008
    #2
    1. Advertising

  3. Dan Hagerman

    Dan Hagerman Guest

    10-4, thanks.

    10-4, thanks.
     
    Dan Hagerman, Dec 23, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2FyYXY=?=

    Upload a file without file Upload control - ASP.Net

    =?Utf-8?B?U2FyYXY=?=, Aug 2, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,585
    Bruce Barker
    Aug 3, 2005
  2. Replies:
    5
    Views:
    415
  3. Dan Hagerman
    Replies:
    1
    Views:
    1,659
    Tamer Öz
    Dec 25, 2008
  4. AbuTalhah

    Upload files from Pocket PC

    AbuTalhah, Aug 2, 2004, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    129
    AbuTalhah
    Aug 2, 2004
  5. dsnyder
    Replies:
    2
    Views:
    581
    David Snyder
    Apr 14, 2004
Loading...

Share This Page