public ActionResult DownLoad(string treqCode) { FileInfoFtp file = CargaDocsService.DisplayFileFromServer( GlobalVariables.Matricula, treqCode, GlobalVariables.Fndc, GlobalVariables.Aidy, GlobalVariables.Aidp); byte[] fileBytes = Convert.FromBase64String(file.FileContent); //File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, "filename"+file.Type); return(File(fileBytes, file.FileType, file.FileName)); }
public static FileInfoFtp DisplayFileFromServer(string matricula, string clave, string fndcCode, string aidyCode, string aidpCode) { Document document = new Document(matricula, clave, fndcCode, aidyCode, aidpCode); if (document.status == "PS") { Console.WriteLine($"Su documento no esta en nuestro sistema!"); throw new HttpException((int)HttpStatusCode.InternalServerError, "Su documento no esta en nuestro sistema!"); } FileInfoFtp file = new FileInfoFtp(clave); WebClient request = new WebClient(); request.Credentials = new NetworkCredential(GlobalVariables.FtpUser, GlobalVariables.FtpPassword); try { Stream streamTemp = null; byte[] newFileData = request.DownloadData(new Uri(GlobalVariables.Ftpip) + "/" + file.FileId); //if (file.FileType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") //{ // Converter toPdf = new Converter(); // toPdf.convert(newFileData,Format.DOCX, streamTemp, Format.PDF); // file.FileContent = GlobalVariables.ConvertToBase64(streamTemp); //} file.FileContent = Convert.ToBase64String(newFileData); } catch (Exception ex) { throw new HttpException((int)HttpStatusCode.InternalServerError, ex.Message); } if (file.FileContent == null) { throw new HttpException((int)HttpStatusCode.InternalServerError, "El Documento no esta en nuestro servidor"); } return(file); }