예제 #1
0
        public DownFileResult DownLoadFile(DownFile filedata)
        {
            DownFileResult result = new DownFileResult();
            string         path   = System.AppDomain.CurrentDomain.BaseDirectory + @"\service\" + filedata.FileName;

            if (!File.Exists(path))
            {
                result.IsSuccess  = false;
                result.FileSize   = 0;
                result.Message    = "服务器不存在此文件";
                result.FileStream = new MemoryStream();
                return(result);
            }
            Stream     ms = new MemoryStream();
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);

            fs.CopyTo(ms);
            ms.Position       = 0; //重要,不为0的话,客户端读取有问题
            result.IsSuccess  = true;
            result.FileSize   = ms.Length;
            result.FileStream = ms;
            fs.Flush();
            fs.Close();
            return(result);
        }
 public DownFileResult DownLoadFile(DownFile filedata)
 {
     DownFileResult result = new DownFileResult();
     string path = System.AppDomain.CurrentDomain.BaseDirectory + @"\service\" + filedata.FileName;
     if (!File.Exists(path))
     {
         result.IsSuccess = false;
         result.FileSize = 0;
         result.Message = "服务器不存在此文件";
         result.FileStream = new MemoryStream();
         return result;
     }
     Stream ms = new MemoryStream();
     FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
     fs.CopyTo(ms);
     ms.Position = 0;  //重要,不为0的话,客户端读取有问题
     result.IsSuccess = true;
     result.FileSize = ms.Length;
     result.FileStream = ms;
     fs.Flush();
     fs.Close();
     return result;
 }