public void Print(string FileName) { using (FileService.FileTransferServiceClient svc = new FileService.FileTransferServiceClient()) { try { DownloadFileResponse response = svc.DownloadFile(new DownloadFileRequest() { TargetContainer = "", TargetFileName = FileName }); if (response.Code == "0000") { if (response.ContentType == "application/pdf") { String fileName = response.FileName.Substring(response.FileName.IndexOf(@"\")); if (String.IsNullOrEmpty(fileName)) { ViewDocument(response.FileByteStream, Convert.ToInt64(response.Length), response.ContentType); } else { ViewDocument(response.FileByteStream, Convert.ToInt64(response.Length), response.ContentType, fileName); } } } } catch (Exception ex) { Response.Write(ex.Message); } } }
protected void btnDownload_Click(object sender, EventArgs e) { using (svc = new FileService.FileTransferServiceClient()) { DownloadFileResponse response = new DownloadFileResponse(); DTO.AttachFile attachFile = ((List <DTO.AttachFile>)Session["AttachFiles"]).FirstOrDefault(); String container = ""; String fileName = ""; response = svc.DownloadFile(new DownloadFileRequest() { TargetContainer = container, TargetFileName = attachFile.TargetFullName }); Page.Response.Clear(); Page.Response.BufferOutput = true; Page.Response.ContentType = response.ContentType; // Append header //Page.Response.AppendHeader("Content-Disposition", "attachment; filename=" + response.FileName); // Write the file to the Response const int bufferLength = 10000; byte[] buffer = new Byte[bufferLength]; int length = 0; Stream download = null; try { download = response.FileByteStream; // GetFile(fileName); do { if (Page.Response.IsClientConnected) { length = download.Read(buffer, 0, bufferLength); Page.Response.OutputStream.Write(buffer, 0, length); buffer = new Byte[bufferLength]; } else { length = -1; } }while (length > 0); Page.Response.Flush(); Page.Response.End(); } finally { if (download != null) { download.Close(); } } } }
public void DownloadPDF(string FileName) { DownloadFileResponse download; using (FileService.FileTransferServiceClient fileService = new FileService.FileTransferServiceClient()) { download = fileService.DownloadFile(new DownloadFileRequest() { TargetContainer = "", TargetFileName = FileName }); ShowDocument(download.FileByteStream, (long)download.Length, download.ContentType); } }
protected void Page_Load(object sender, EventArgs e) { using (FileService.FileTransferServiceClient svc = new FileService.FileTransferServiceClient()) { try { String targetImage = Request.QueryString["targetImage"].ToString(); DownloadFileResponse response = svc.DownloadFile(new DownloadFileRequest() { TargetContainer = "", TargetFileName = CryptoBase64.Decryption(targetImage) }); if (response.Code == "0000") { Int32 index = response.FileName.LastIndexOf(@"\"); String filename = response.FileName.Substring((index > 0) ? index + 1 : 0); if (response.ContentType == Utils.ContentTypeHelper.MimeType(".pdf") || response.ContentType == Utils.ContentTypeHelper.MimeType(".doc") || response.ContentType == Utils.ContentTypeHelper.MimeType(".docx") || response.ContentType == Utils.ContentTypeHelper.MimeType(".xls") || response.ContentType == Utils.ContentTypeHelper.MimeType(".xlsx")) { ShowDocument(response.FileByteStream, Convert.ToInt64(response.Length), response.ContentType, filename); } else if (response.ContentType == "application/octet-stream" && (filename.Substring(filename.LastIndexOf('.')) == ".docx" || filename.Substring(filename.LastIndexOf('.')) == ".doc" || filename.Substring(filename.LastIndexOf('.')) == ".xls" || filename.Substring(filename.LastIndexOf('.')) == ".xlsx" )) { ShowDocument(response.FileByteStream, Convert.ToInt64(response.Length), Utils.ContentTypeHelper.MimeType(filename.Substring(filename.LastIndexOf('.'))), filename); } else { ShowImage(response.FileByteStream, Convert.ToInt64(response.Length), response.ContentType, filename); } } } catch (Exception ex) { Response.Write(ex.Message); } } }
public void Download(string FileName) { DownloadFileResponse download; using (FileService.FileTransferServiceClient fileService = new FileService.FileTransferServiceClient()) { download = fileService.DownloadFile(new DownloadFileRequest() { TargetContainer = "", TargetFileName = FileName }); Int32 indexS = download.FileName.IndexOf(@"\"); if (indexS <= 0) { ShowDocument(download.FileByteStream, (long)download.Length, download.ContentType); } else { ShowDocument(download.FileByteStream, (long)download.Length, download.ContentType, download.FileName.Substring(indexS + 1)); } } }
protected void gv_SelectedIndexChanged(object sender, EventArgs e) { DTO.AttachFile attachFile = ((List <DTO.AttachFile>)Session["AttachFiles"]).FirstOrDefault(); String container = ""; String fileName = gv.Rows[gv.SelectedIndex].Cells[7].Text; using (svc = new FileService.FileTransferServiceClient()) { DownloadFileResponse response = new DownloadFileResponse(); response = svc.DownloadFile(new DownloadFileRequest() { TargetContainer = container, TargetFileName = IAS.Utils.CryptoBase64.Decryption(fileName) }); if (response.Code == "0000") { ShowImage(response.FileByteStream, Convert.ToInt64(response.Length)); } } // Page.Response.Clear(); // Page.Response.BufferOutput = true; // Page.Response.ContentType = response.ContentType; // // Append header // Page.Response.AppendHeader("Content-Disposition", "attachment; filename=" + response.FileName); // // Write the file to the Response // //const int bufferLength = Convert.ToInt32(response.Length); // byte[] buffer = new Byte[Convert.ToInt32(response.Length)]; // //int length = 0; // //Stream download = null; // //response.FileByteStream.Write(buffer, 0, Convert.ToInt32(response.Length)); // //myImage.ImageUrl = Convert.ToBase64String(buffer).ToString(); // using (var memoryStream = new MemoryStream()) // { // response.FileByteStream.CopyTo(memoryStream); // buffer = memoryStream.ToArray(); // } // myImage.ImageUrl = Convert.ToBase64String(buffer).ToString(); // //try // //{ // // download = response.FileByteStream; // etFile(fileName); // // do // // { // // if (Page.Response.IsClientConnected) // // { // // length = download.Read(buffer, 0, bufferLength); // // Page.Response.OutputStream.Write(buffer, 0, length); // // myImage.ImageUrl = Convert.ToBase64String(buffer).ToString(); // // buffer = new Byte[bufferLength]; // // } // // else // // { // // length = -1; // // } // // } // // while (length > 0); // // Page.Response.Flush(); // // Page.Response.End(); // //} // //finally // //{ // // if (download != null) // // download.Close(); // //} //} }