다운로드 후 파일에 오류가 발생했습니다.
-
17-09-2020 - |
문제
서버에서 완벽하게 열리는 워드 문서가 있는데 내 웹사이트의 버튼 클릭 이벤트를 사용하여 다운로드하면 문제가 발생합니다.문서 다운로드를 위해 버튼 클릭 시 아래 코드를 사용하고 있습니다.이 문제를 해결하는 데 도움을 주세요:저는 .net 프레임워크 3.5를 사용하고 있습니다.
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=StandardLetter" + _responseId.ToString() + ".doc");
Response.ContentType = "application/octet-stream";
Response.TransmitFile (Server.MapPath("~/document/letter/StandardLetter" + _responseId.ToString() + ".doc"));
해결책
OK 여기서는 사용하는 코드가 있습니다. VB이지만 쉽게 변환됩니다.)
Response.ContentType = "application/pdf"
Dim byteArray As Byte() = File.ReadAllBytes(MergedFile)
Response.AddHeader("Content-Disposition", "attachment;filename=""" & ShortFilename & """")
Response.AddHeader("Content-Length", byteArray.Length)
Response.BinaryWrite(byteArray)
Response.Flush()
Response.End()
.
이것은 PDF를 위해 작품이며 .contentType을 엑셀로 바꾸어서 excel이 밖으로 나가는 것을 느낄 수 있습니다. 그래서 이것은 MIME 유형이 걸릴 것으로 가정합니다.행운을 빌어!
i MergedFile이라는 PDF 문서를 사용하여 Byte ()로 변환하십시오. 사용자가 입력 할 수있는 'ShortName'을 제공합니다.콘텐츠 길이는 매우 중요합니다 ..
다른 팁
대신 시도해보십시오 :
Response.ContentType ="application/msword";
.
나는 단어를 사용하지 않지만 엑셀의 경우 :
Response.ContentType = "application/x-msexcel"
. 제휴하지 않습니다 StackOverflow