Windows Mobile Developer Center > Smart Device Development Forums > .NET Compact Framework > Http Image File Uploader for .net compact framework 2.0
Ask a questionAsk a question
 

AnswerHttp Image File Uploader for .net compact framework 2.0

  • Thursday, June 29, 2006 8:11 AMa_Stoic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Having major problems trying to upload a file (an image) to a webserver via http post, keep getting a WebException..
    Tried using the example code available at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/httpcomm.asp

    ---------- Code --------------
    private void menuItem2_Click(object sender, EventArgs e) {
        String httpResponce = UploadFileBinary(@"\Storage Card\test.jpg", http://www.myServer.com/upload.php);
       
    MessageBox.Show(httpResponce);
    }

    public String UploadFileBinary(string localFile, string uploadUrl) {
        Cursor.Current = Cursors.WaitCursor;
       
    HttpWebRequest req = (HttpWebRequest) WebRequest.Create(uploadUrl);
        req.Method =
    "PUT";
        req.AllowWriteStreamBuffering =
    true;

        // Retrieve request stream 
       
    Stream reqStream = req.GetRequestStream();

        // Open the local file
       
    FileStream rdr = new FileStream(localFile, FileMode.Open);

        // Allocate byte buffer to hold file contents
       
    byte[] inData = new byte[4096];

        // loop through the local file reading each data block
        // and writing to the request stream buffer
       
    int bytesRead = rdr.Read(inData, 0, inData.Length);
       
    while(bytesRead > 0) {
            reqStream.Write(inData, 0, bytesRead);
            bytesRead = rdr.Read(inData, 0, inData.Length);
        }

        rdr.Close();
        reqStream.Close();
        req.GetResponse();
       
    Cursor.Current = Cursors.Default;
       
    return "UploadFileBinary: Okay so far..";
    }


    ---------- Error Msg --------------
    HttpUpload.exe
    WebException
    An error message cannot be displayed because an optional resource assembly containing it cannot be found

    at System.Net.HttpWebRequest.finishGetResponse()
    at System.Net.HttpWebRequest.GetResponse()
    at HttpUpload.Form1.UploadFileBinary()
    at HttpUpload.Form1.menuItem2_Click()
    at System.Windows.Forms.MenuItem.OnClick()
    at System.Windows.Forms.Menu.ProcessMnuProc()
    at System.Windows.Forms.Form.WnProc()
    at System.Windows.Forms.Control._InternalWnProc()
    at Microsoft.AGL.Forms.EVL.EnterMainLoop()
    at System.Windows.Forms.Application.Run()
    at HttpUpload.Program.Main()

    thanks..

Answers

  • Thursday, June 29, 2006 7:28 PMIlya TumanovMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    You've installed SR CAB for NETCF V1 but you're using NETCF V2. By default correct cab should be here:

    C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\v2.0\WindowsCE\Diagnostics

    If you've installed NETCF V2 to custom folder it might be in a different place, please search your PC to find actual location.

  • Friday, June 30, 2006 12:25 AMIlya TumanovMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Strange, that should’ve fixed it and there should be no reboot request.

    Can you see that CAB in “Remove Programs” applet?  Also, what is the locale of your device?

All Replies

  • Thursday, June 29, 2006 2:31 PMa_Stoic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    ---------- Additional Info --------------
    Tested on: i-mate KJam and i-mate SP5, with NETCF 2.0 and after upgrade to NETCF 2.0 SP1;

    seems to be dying on the req.GetResponse(); line..

  • Thursday, June 29, 2006 3:56 PMIlya TumanovMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Please install SR CAB to get actual error message.

     

    If that's your actual code, I doubt that particular server would let you upload anything on to it, so error is expected.

     

    If you using your own server which actually allow uploads, it might be an issue with server and/or network.

     

  • Thursday, June 29, 2006 6:52 PMa_Stoic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Installed both "System_SR_ENU.cab" and "System_SR_ENU_wm.cab" from the VS2005 directory below and re-ran my app but the error message dosent change, still get "An error message cannot be displayed because an optional resource assembly containing it cannot be found", is their another resource that should be installed?

    Dir: C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\v1.0\WindowsCE\Diagnostics

  • Thursday, June 29, 2006 7:25 PMAlexFeinmanMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Do you really expect http://www.google.com to accept file uploads?
  • Thursday, June 29, 2006 7:28 PMIlya TumanovMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    You've installed SR CAB for NETCF V1 but you're using NETCF V2. By default correct cab should be here:

    C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\v2.0\WindowsCE\Diagnostics

    If you've installed NETCF V2 to custom folder it might be in a different place, please search your PC to find actual location.

  • Thursday, June 29, 2006 11:45 PMa_Stoic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    That’s just fictitious url for the code demo (not like I can post the actual one)..

  • Friday, June 30, 2006 12:01 AMa_Stoic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Opps! Found the right one.. 
    Dir: C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\Diagnostics

    Again installed "System_SR_ENU_wm.cab" got the restart your device message which i did, then re-tested the code and still get the error message "An error message cannot be displayed because an optional resource assembly containing it cannot be found"..

    Am i missing anything else..

  • Friday, June 30, 2006 12:25 AMIlya TumanovMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Strange, that should’ve fixed it and there should be no reboot request.

    Can you see that CAB in “Remove Programs” applet?  Also, what is the locale of your device?

  • Friday, June 30, 2006 12:36 AMahmedilyasMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Just to add to the CAB file problem I still have this problem also, even though it displays it in the control panel/add remove programs on the device
  • Friday, June 30, 2006 12:01 PMa_Stoic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    locale of my device..
    Language: US English
    Local: English (United Kingdom)

    Checked under “Remove Programs” it appears as.
    - Microsoft .Net CF 2.0 ENU-String resource            0.0K
    also found..
    - Microsoft .Net CF 1.0 ENU-String resource            0.0K

    Removed both and just put the 2.0 back on, still appeared as 0.0 K..
    - Microsoft .Net CF 2.0 ENU-String resource            0.0K

    Now it WORKS ;-) 

     

    Nb. Very strange, wish VS2005 would deploy this by default when you debug an app..

    ahh! well somthing to look forward to in the next release :-)

     

     

  • Friday, July 14, 2006 3:01 AMKangaroo_Marco Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have exactly the same case as you have. I have studeied for 2 weeks, still cannot find the solution.  but my case seems more special. I have this exception only when I switch my locale to Chinese. for the deault locae, my program runs smooth. I have also tested for the internet destination. There is no log record appear in the server for my PPC request.

    One more point is I can run smooth of this program in chinese locale on the PPC which is on PPC 2003 SE OS.

    Please help
  • Saturday, July 22, 2006 12:37 PMbergtatt Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    hello,

    I have similar problems, code is similar to _Stoic's, i am sending an xml file tho'. I get similar stack trace, but the WebException message is   "The remote server returned an error: (500) Internal Server Error." - I cannot explain this because on a similar product ( mobile phones ) saving data to server works just fine and server does not return internal errors.

    If someone has found answer to this issue, please post here.

    thanks.

  • Tuesday, October 10, 2006 3:13 AMManjuramu Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hello...

    Regarding the Assembly Resource Error, the method used i.e. PUT is not implemented on the server. So Instead of PUT use POST.

    Check it out and let me know.

    With Regards,

    Manjunath

  • Thursday, October 26, 2006 1:21 PMTryst Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have two cab files, which one should I install on the device?

    System_SR_ENU.CAB, or
    System_SR_ENU_wm.cab.

    Also, what is the benefit of install in these files? Is it because it gives you more descriptive error messages when your debugging?

    Thanks

    Tryst