日期:2014-05-20  浏览次数:20627 次

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);