wp7 怎么上传文件?

June1991 2011-12-21 10:19:33
wp7 怎么上传文件?
...全文
1080 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
June1991 2012-01-05
  • 打赏
  • 举报
回复
嗯,是MessageBox的问题,但为什么服务器收不到压缩包呢?
zaiguo 2011-12-31
  • 打赏
  • 举报
回复
或者试试
Deployment.Current.Dispatcher.BeginInvoke(()=>MessageBox.Show(strResponese));
zaiguo 2011-12-31
  • 打赏
  • 举报
回复
MessageBox.Show(strResponese);
出问题了吧!ui不是一个线程的!去掉试试?
keeya0416 2011-12-27
  • 打赏
  • 举报
回复
楼主搜下 multipart 就行了
代码太多 我就懒得贴了
June1991 2011-12-27
  • 打赏
  • 举报
回复
上传的是压缩文件到服务器,然后服务器解压缩。
June1991 2011-12-27
  • 打赏
  • 举报
回复
 try
{
HttpWebRequest request = result.AsyncState as HttpWebRequest;
WebResponse response = request.EndGetResponse(result) as HttpWebResponse;
if (response != null)
{
Stream responseStream = response.GetResponseStream();
using (StreamReader streamReader = new StreamReader(responseStream))
{
String strResponese = streamReader.ReadToEnd();//返回内容
MessageBox.Show(strResponese);
}
}
}
catch (Exception ex)
{
String strError = ex.ToString();
}

在这个是strError strResponese返回了 \r\n
pirates_fish 2011-12-26
  • 打赏
  • 举报
回复
June1991 2011-12-26
  • 打赏
  • 举报
回复
private byte[] bSendingFile = null;

 private void Update()
{
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream sendingZipStream = new IsolatedStorageFileStream(Used.strZipPath, FileMode.Open, isf))
{
try
{
// 要上传的文件
bSendingFile = new byte[sendingZipStream.Length];
sendingZipStream.Read(bSendingFile, 0, bSendingFile.Length);
// 根据uri创建HttpWebRequest对象
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(new Uri(Used.strUpdateUrl, UriKind.Absolute));
httpReq.Method = "POST";
httpReq.ContentType = "multipart/form-data;";
IAsyncResult asyncResult = httpReq.BeginGetRequestStream(new AsyncCallback(RequestStreamCallback), httpReq);
}
catch (Exception ex)
{
String strError = ex.ToString();
}
}
}
}
/// <summary>
/// 返回用于将数据写入Stream,写入数据,并发送
/// </summary>
/// <param name="result"></param>
private void RequestStreamCallback(IAsyncResult result)
{
HttpWebRequest request = result.AsyncState as HttpWebRequest;
// 返回用于将数据写入某 URI 资源的 Stream
Stream requestStream = request.EndGetRequestStream(result);
requestStream.Write(bSendingFile, 0, bSendingFile.Length);
requestStream.Flush();
requestStream.Close();
request.BeginGetResponse(new AsyncCallback(ResponseCallback), request);
}
/// <summary>
/// 获取最终的返回结果
/// </summary>
/// <param name="result"></param>
private void ResponseCallback(IAsyncResult result)
{
try
{
HttpWebRequest request = result.AsyncState as HttpWebRequest;
WebResponse response = request.EndGetResponse(result) as HttpWebResponse;
if (response != null)
{
Stream responseStream = response.GetResponseStream();
using (StreamReader streamReader = new StreamReader(responseStream))
{
String strResponese = streamReader.ReadToEnd();//返回内容
MessageBox.Show(strResponese);
}
}
}
catch (Exception ex)
{
String strError = ex.ToString();
}
}


这样写可以么?
beyondma 2011-12-26
  • 打赏
  • 举报
回复
楼上这个错是哪句报的?一般很少有在智能手机上上传文件的例子。为什么这样做?
June1991 2011-12-26
  • 打赏
  • 举报
回复
{System.UnauthorizedAccessException: Invalid cross-thread access at MS.Internal.XcpImports.CheckThread()
at MS.Internal.XcpImports.MessageBox_ShowCore(String messageBoxText, String caption, UInt32 type)
at System.Windows.MessageBox.ShowCore(String messageBoxText, String caption, MessageBoxButton button)
at System.Windows.MessageBox.Show(String messageBoxText)
at gzip.MainPage.ResponseCallback(IAsyncResult result)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassa.<InvokeGetResponseCallback>b__8(Object state2)
at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadPool.WorkItem.doWork(Object o)
at System.Threading.Timer.ring()
}
June1991 2011-12-23
  • 打赏
  • 举报
回复
WebClient 好像不行吧!
gnimgnot 2011-12-21
  • 打赏
  • 举报
回复
WebClient.UploadFile

7,655

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧