문제

가장 좋은 방법은 무엇을 구현 웹 페이지에서 다운로드를 사용하여 작업 asp.net 2.0?

기 위해 로그 파일을 작업에서 만들어 라는 디렉토리[응용 프로그램 루트]/로그입니다.나는 전체 경로를 제공하고 싶다면 버튼을 클릭하면 해당 로그 파일을 다운로드에서 IIS 서버 사용자는 로컬 pc.

도움이 되었습니까?

해결책

이 도움말:

http://www.west-wind.com/weblog/posts/76293.aspx

Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition","attachment; filename=logfile.txt");
Response.TransmitFile( Server.MapPath("~/logfile.txt") );
Response.End();

응답입니다.TransmitFile 은 받아들의 방법으로 대용량 파일을 전송하는 대신에,응답입니다.WriteFile.

다른 팁

http://forums.asp.net/p/1481083/3457332.aspx

string filename = @"Specify the file path in the server over here....";
FileInfo fileInfo = new FileInfo(filename);

if (fileInfo.Exists)
{
   Response.Clear();
   Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
   Response.AddHeader("Content-Length", fileInfo.Length.ToString());
   Response.ContentType = "application/octet-stream";
   Response.Flush();
   Response.TransmitFile(fileInfo.FullName);
   Response.End();
}


업데이트:

초기 코드

Response.AddHeader("Content-Disposition", "inline;attachment; filename=" + fileInfo.Name);

는"인라인;첨부 파일을"i.e두 값의 콘텐츠에 대한 처분에 있습니다.

알 수 없을 때 정확하게 시작했지만,파이어 폭스 적절한 파일의 이름은 표시되지 않습니다.파일 다운로드 상자와 함께 나타납의 이름 웹 페이지의 확장자(pagename.aspx).다운로드 후,이름을 변경하는 경우 그것을 다시 실제 이름파일이 열립니다.

당로 이 페이지, 동 선착순에 기초.값을 변경하기 attachment 만 해결 문제입니다.

PS:나는 확실하지 않은 경우는 것이 최상의 방법입니다 하지만 문제가 해결되었는지 확인합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top