내 응용 프로그램에서 사용자에게 PDF 파일을 다운로드 할 수있는 옵션을 제공하고 싶습니다. 내 코드에서 파일은 브라우저에서 열립니다. 그러나 파일을 다운로드하려고합니다. 내가 드롭 다운 메뉴에서 사용하고 방법은 다음과PDF 파일 다운로드 C#
컨트롤러
string name = id; //id is the name of the file
string contentType = "application/pdf";
var files = objData.GetFiles(); //list of files
string filename = (from f in files
orderby f.DateEncrypted descending
where f.FileName == name
select f.FilePath).First(); //gets the location of the file
string FullName = (from f in files
where f.FileName == name
select f.FileName).First(); //gets the new id in new location to save the file with that name
//Parameters to File are
//1. The File Path on the File Server
//2. The content type MIME type
//3. The parameter for the file save by the browser
return File(filename, contentType, FullName);
: 여기에 내 코드입니다.
보기 :
<li><a id="copyURL" href="@Url.Action("Download", "Home", new { id = item.FileName})">Download</a></li>
"다운로드"를 클릭하여이 파일은 브라우저를 열어됩니다.
브라우저가 계속 열려고합니다. 나는 크롬과 IE로 그것을 시도했다. – user3853986
return 문 앞에이 줄을 추가해 볼 수 있습니까? 'Response.AddHeader ("content-disposition", "attachment; filename ="+ filename); ' –
여전히 동일합니다. 나는 시도했다 Response.AddHeader ("content-disposition", "attachment; filename ="+ filename); 및 Response.AddHeader ("content-disposition", "attachment; filename ="+ FullName); – user3853986