我需要将文件与来自 windows phone 的 xml 字符串一起发送到服务器。
下面是服务器端 IhttpHandler 代码。
现在请给我一些 Windows Phone 的代码示例,1 个大文件可以上传到服务器,还可以通过 POST 上传 xml 或任何字符串?
在服务器端代码下方
<%@ WebHandler Language="C#" Class="Test" %>
using System;
using System.Web;
using System.IO;
public class Test : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write(AddSurveyMediaWithFile(context.Request.Files[0] , context.Request["MediaDataXML"].ToString()));
}
public bool IsReusable {
get {
return false;
}
}
public string ShowMessage(string msg)
{
return msg;
}
public String AddSurveyMediaWithFile(HttpPostedFile uploadedFile, string MediaDataXML)
{
try
{
Survey.AddDataMediaXMLCheck(MediaDataXML, "Media");
string FilePath = HttpContext.Current.Server.MapPath("../MediaFiles/");
AttributeValue objAttributeValue = ParseValue(MediaDataXML);
objAttributeValue.Value = objAttributeValue.Value;
OrganizationUnitLicense objLicense = OrganizationUnitLicense.ValidateFilesize(objAttributeValue.UserWorkUnitSurveyID);
if (objAttributeValue.Filesize > 0)
{
if (objLicense.Space > 0)
{
if ((objLicense.TotalFilesize + objAttributeValue.Filesize) <= (objLicense.Space * 1024 * 1024))
{
string msg = Survey.AddSurveyData(MediaDataXML);
if (msg == Enumerators.SQLReturn.SUCCESS.ToString())
{
if (File.Exists(FilePath + objAttributeValue.Value))
File.Delete(FilePath + objAttributeValue.Value);
uploadedFile.SaveAs(FilePath + objAttributeValue.Value);
return Enumerators.SQLReturn.SUCCESS.ToString();
}
else
{
return msg;
}
}
else
{
return "FILESIZE_" + Enumerators.SQLReturn.LIMIT_NOT_EXIST.ToString();
}
}
else
{
string msg = Survey.AddSurveyData(MediaDataXML);
if (msg == Enumerators.SQLReturn.SUCCESS.ToString())
{
if (File.Exists(FilePath + objAttributeValue.Value))
File.Delete(FilePath + objAttributeValue.Value);
uploadedFile.SaveAs(FilePath + objAttributeValue.Value);
return Enumerators.SQLReturn.SUCCESS.ToString();
}
else
{
return msg;
}
}
}
else
{
return "FILESIZE_ZERO";
}
}
catch (Exception ex)
{
return ex.Message + Environment.NewLine + ex.StackTrace; //Enumerators.SQLReturn.ERROR.ToString();
}
}
private AttributeValue ParseValue(string MediaDataXML)
{
..... //to do section
}
}