首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

android调用webservice上传文件的有关问题

2013-12-05 
android调用webservice上传文件的问题我在webservice里写了一个方法来让android上传文件,上传文件模仿的是

android调用webservice上传文件的问题
我在webservice里写了一个方法来让android上传文件,上传文件模仿的是html的input type=file。

System.Collections.Generic.List<string> filePaths = new System.Collections.Generic.List<string>();
                            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";
                            }

这是接收文件部分的代码  请问是否有错? android端应该如何写?
网上的都是上传图片的  我需要的是上传任何文件的。android调用webservice上传文件的有关问题 webservice android .net
[解决办法]
你找到上传图片的方法是用什么方式上传的?看看介个

热点排行