/// <summary> /// 下载 /// </summary> /// <returns></returns> public bool DownloadFile(string iiid, string dataid) { var usercenterService = GetService <UserCenterService>(); usercenterService.AddDownLoad(PKSUser.Identity.Id.ToInt32(), iiid); try { DownloadRequest downloadRequest = new DownloadRequest(); downloadRequest.DataId = dataid; downloadRequest.Source = true; downloadRequest.Download = true; var response = AppDataService.Download(downloadRequest); byte[] bytes = new byte[(int)response.Content.Length]; response.Content.Read(bytes, 0, bytes.Length); response.Content.Close(); Response.ContentType = response.ContentType; //Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(response.FileName, System.Text.Encoding.UTF8)); Response.AddHeader("Content-Disposition", "attachment; filename=" + response.FileName); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); } catch (Exception e) { string content = "下载失败:\r\n" + e.Message; byte[] bytes = Encoding.UTF8.GetBytes(content); Response.ContentType = "text/plain"; Response.AddHeader("Content-Disposition", "attachment; filename=error.txt"); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); } return(true); }