3
我正在爲windows phone 7開發應用程序。從這裏我想上傳一個圖像文件到遠程server.I使用以下代碼接收文件在我的接收端:在windows phone 7應用程序中發佈圖像文件
if (Request.Files.Count > 0)
{
string UserName = Request.QueryString["SomeString"].ToString();
HttpFileCollection MyFilecollection = Request.Files;
string ImageName = System.Guid.NewGuid().ToString() + MyFilecollection[0].FileName;
MyFilecollection[0].SaveAs(Server.MapPath("~/Images/" + ImageName));
}
現在我的問題是,如何從(使用PhotoChooserTask)。我曾嘗試下面的代碼,但沒有成功我的Windows Phone 7平臺發佈的文件(以下代碼從PhotoChooserTask叫完成事件處理程序
private void UploadFile(string fileName, Stream data)
{
char[] ch=new char[1];
ch[0] = '\\';
string [] flname=fileName.Split(ch);
UriBuilder ub = new UriBuilder("http://www.Mywebsite.com?SomeString="+ussi);
ub.Query = string.Format("name={0}", flname[6]);
WebClient c = new WebClient();
c.OpenWriteCompleted += (sender, e) =>
{
PushData(data, e.Result);
e.Result.Close();
data.Close();
};
c.OpenWriteAsync(ub.Uri);
}
private void PushData(Stream input, Stream output)
{
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) != 0)
{
output.Write(buffer, 0, bytesRead);
}
}
請幫我拿到擺脫這個問題。 謝謝