1, mobile phone side
private void Btnuploadpic_click (object sender, RoutedEventArgs e)
{
Photochoosertask pct = new Photochoosertask ();
pct. Showcamera = true;
pct.completed + = new eventhandler<photoresult> (pct_completed);
pct. Show ();
}
void Pct_completed (object sender, Photoresult e)
{
if (E.taskresult = = Taskresult.ok)
{
WebClient WC = new WebClient ();
Wc. openwritecompleted + = new Openwritecompletedeventhandler (wc_openwritecompleted);
Wc. writestreamclosed + = new Writestreamclosedeventhandler (wc_writestreamclosed);
Wc. OpenWriteAsync (New Uri ("Http://127.0.0.1:21299/MyNoteWeb/ashx/UpLoadImg.ashx"), "POST", E.chosenphoto);
}
}
void Wc_writestreamclosed (object sender, Writestreamclosedeventargs e)
{
if (e.error = = null)
{
messagebox.show ("Upload succeeded");
Else
{
messagebox.show ("Upload failed");
}
}
void Wc_openwritecompleted (object sender, OpenWriteCompletedEventArgs e)
{
if (E.error = = null)
{
using (Stream photostream = (stream) e.userstate)
{
Photostream.copyto (E.result);
E.result.close ();
}
}
}
2, (ASP) server:
public void ProcessRequest (HttpContext context) {
Context. Response.ContentType = "text/html";
UpLoad (context);
Context. Response.End ();
}
private static void UpLoad (HttpContext context)
{
using (FileStream fs = File.openwrite ("c:/1.jpg"))
{
Context. Request.InputStream.CopyTo (FS);
}
}
Windows Phone 7 uploading pictures