I have a problem downloading PDF files. while other files load. code:
WebClient client = new WebClient(); client.DownloadFile(remoteFilename, localFilename);
Help me if you know
check this method, hope it helps
public static void DownloadFile(HttpResponse response,string fileRelativePath) { try { string contentType = ""; //Get the physical path to the file. string FilePath = HttpContext.Current.Server.MapPath(fileRelativePath); string fileExt = Path.GetExtension(fileRelativePath).Split('.')[1].ToLower(); if (fileExt == "pdf") { //Set the appropriate ContentType. contentType = "Application/pdf"; } //Set the appropriate ContentType. response.ContentType = contentType; response.AppendHeader("content-disposition", "attachment; filename=" + (new FileInfo(fileRelativePath)).Name); //Write the file directly to the HTTP content output stream. response.WriteFile(FilePath); response.End(); } catch { //To Do } }
Please try the following code sample to download the .pdf file.
Response.ContentType = "Application/pdf"; Response.AppendHeader("Content-Disposition", "attachment; filename=Test_PDF.pdf"); Response.TransmitFile(Server.MapPath("~/Files/Test_PDF.pdf")); Response.End();
@Syed Mudhasir: Its just a string :)
client.DownloadFileAsync(new Uri(remoteFilename, UriKind.Absolute), localFilename);
It will download pdf files. :)
This worked for me:
string strURL = @"http://192.168.1.xxx/" + sDocumento; WebClient req = new WebClient(); HttpResponse response = HttpContext.Current.Response; response.Clear(); response.ClearContent(); response.ClearHeaders(); response.Buffer = true; response.AddHeader("Content-Disposition", "attachment;filename=\"" + sDocumento + "\""); byte[] data = req.DownloadData(strURL); response.BinaryWrite(data); response.End();
Source: https://habr.com/ru/post/1334888/More articles:What does the value of HTML Tidy Config mean to place each tag on a new line? - htmlEntity Syntax Analysis - c #How to invite facebook app? - c #Backspacing in Bash - bashWill there be the following memory issues? - c ++Django: Where to place global models? - pythonoracle sql to display all dates of the previous month - sqlRepeatButton TouchDown - .netjavascript object - private methods: which way is better - performanceFirst request slow for Firebird - performanceAll Articles