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..

Http Image File Uploader for .net compact framework 2.0
Malik01
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
Ruud Poutsma
Matt Stum
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
Maeestro
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
Jimmy_fingers
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 :-)
MartinMalek
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
JohnWP
BoomRShine
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
Florim
That’s just fictitious url for the code demo (not like I can post the actual one)..
rternier
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..
pcompassion
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.
corblet
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.
rlnd
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.
Joshizzle
---------- 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..