서버에서 로컬 호스트로 파일을 다운로드하고 싶습니다.서버 asp.net에서 파일 다운로드
은 내가 작업을해야하지만, 버튼을 로컬 호스트 컴퓨터로 서버에서 다운로드해야 할 파일을 클릭 지금
protected void Button4_Click(object sender, EventArgs e)
{
//To Get the physical Path of the file(test.txt)
string filepath = Server.MapPath("test.txt");
// Create New instance of FileInfo class to get the properties of the file being downloaded
FileInfo myfile = new FileInfo(filepath);
// Checking if file exists
if (myfile.Exists)
{
// Clear the content of the response
Response.ClearContent();
// Add the file name and attachment, which will force the open/cancel/save dialog box to show, to the header
Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);
// Add the file size into the response header
Response.AddHeader("Content-Length", myfile.Length.ToString());
// Set the ContentType
Response.ContentType = ReturnExtension(myfile.Extension.ToLower());
// Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
Response.TransmitFile(myfile.FullName);
// End the response
Response.End();
}
}
private string ReturnExtension(string fileExtension)
{
switch (fileExtension)
{
case ".htm":
case ".html":
case ".log":
return "text/HTML";
case ".txt":
return "text/plain";
case ".doc":
return "application/ms-word";
case ".tiff":
case ".tif":
return "image/tiff";
case ".asf":
return "video/x-ms-asf";
case ".avi":
return "video/avi";
case ".zip":
return "application/zip";
case ".xls":
case ".csv":
return "application/vnd.ms-excel";
case ".gif":
return "image/gif";
case ".jpg":
case "jpeg":
return "image/jpeg";
case ".bmp":
return "image/bmp";
case ".wav":
return "audio/wav";
case ".mp3":
return "audio/mpeg3";
case ".mpg":
case "mpeg":
return "video/mpeg";
case ".rtf":
return "application/rtf";
case ".asp":
return "text/asp";
case ".pdf":
return "application/pdf";
case ".fdf":
return "application/vnd.fdf";
case ".ppt":
return "application/mspowerpoint";
case ".dwg":
return "image/vnd.dwg";
case ".msg":
return "application/msoutlook";
case ".xml":
case ".sdxl":
return "application/xml";
case ".xdp":
return "application/vnd.adobe.xdp+xml";
default:
return "application/octet-stream";
}
}
를 작동하지 않는 인터넷에서 코드를 가지고 ...하지만 아무것도 보이지 않는다
내가이 세 레르 족의 바탕 화면에있는 test.txt이 ... 일이 될 ... 저장 파일 옵션은 나는 파일을 게시 .. 클라이언트 측에서 와서 넣어하지 않습니다 서버의 inetpub 폴더에 있고 클라이언트에서 GUI를 실행하십시오. 면은 ... 모든 것을 대신 내가 내 모든 위치에서 다운로드 할 ...제안
이 ...는 Inetpub 폴더에있는 경우이 프로그램은 파일을 다운로드도와주세요 ...이를 제외하고 작동 서버 ...
??
보통 신뢰 웹 응용 프로그램은 응용 프로그램 경로 외부의 파일에 액세스 할 수 없습니다. 아마도 앱의 권한을 높이는 것이 좋습니다. http://msdn.microsoft.com/ko-kr/library/tkscy493.aspx 물론, 이는 새로운 보안 문제를 야기합니다. –
하지만 로그인 중이며 사용자를 가장 한 경우 ... 가장하지 않은 경우 다운로드하지 않을 것입니다. 다른 것이 있습니다. – user175084