Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > File upload Pocket PC -> Web page, code examples

Reply
Thread Tools

File upload Pocket PC -> Web page, code examples

 
 
Dan Hagerman
Guest
Posts: n/a
 
      12-23-2008
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'd rather fix the Pocket PC
code vs. the web page code, since I know that works for uploads via HTML, but
if I need to change that end of things, so be it. 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
----------------------------------------------------------

 
Reply With Quote
 
 
 
 
Tamer Öz
Guest
Posts: n/a
 
      12-25-2008
Try using web services.

Here is an example.

Mobile App

Stream objStream;
byte[] parFile;
objStream = File.Open(wtbFilePath.Value.ToString().ToLower(), FileMode.Open, FileAccess.Read);
parFile = new byte[objStream.Length];
objStream.Read(parFile, 0, ((int)objStream.Length));
objStream.Close();

BTLMobileLayers.File.Files insFiles = new BTLMobileLayers.File.Files();
try
{

insFiles.FileUpload(fileNameHere, parFile);
}
catch (System.Web.Services.Protocols.SoapException ex)
{

}

Web Service

public void FileUpload(string fileName, byte[] objFile)
{


string root = System.Configuration.ConfigurationManager.AppSetti ngs["root"];

if (!File.Exists(root + fileName))
{
Stream objFileStream = File.Open(root + fileName, FileMode.Create, FileAccess.Write);
objFileStream.Write(objFile, 0, objFile.Length);
objFileStream.Close();

}
else
{
throw new Exception("File Exists");
}
}
"Dan Hagerman" <(E-Mail Removed)> wrote in message news(E-Mail Removed)...
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'd rather fix the Pocket PC
code vs. the web page code, since I know that works for uploads via HTML, but
if I need to change that end of things, so be it. 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
----------------------------------------------------------

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File upload from Pocket PC to web page, code examples Dan Hagerman ASP General 2 12-23-2008 07:47 PM
RESUME EXAMPLES INFORMATION / CV EXAMPLES NOW AVAILABLE THROUGHRESUMEWRITERGUIDE.COM rawebadvert3 Computer Support 0 03-23-2008 04:19 AM
COVER LETTERS RESUME EXAMPLES AND CV EXAMPLES AVAILABLE CURRICULUM VITAE rawebadvert3 Computer Support 0 08-21-2007 03:07 AM
COVER LETTERS RESUME EXAMPLES AND CV EXAMPLES AVAILABLE rawebadvert3 Computer Support 0 05-25-2007 04:18 AM
Setting initial focus in html using Javascript - Pocket IE on Windows 2003 Pocket PC dsnyder Javascript 2 04-14-2004 03:58 PM



Advertisments