2010-06-21 3 views
8

파일을 다운로드 할 때 파일 이름을 바꿀 수 있습니까? 예를 들어, ID를 사용하여 폴더에 파일을 저장하고 싶지만 사용자가 파일을 다운로드 할 때 원래 파일 이름을 반환하고 싶습니다.다운로드 요청시 파일 이름을 동적으로 바꿉니다.

+1

대 위에 파일의 이름을 변경 조금 더 줄 수 있어요? 세부 사항, 특히 파일이 클라이언트에 어떻게 다운로드되고 있습니까? – CodingGorilla

+1

* lot * 자세한 정보는 여기에 제공해야합니다. 파일을 다운로드하는 이유는 무엇입니까? 귀하의 코드는 어디에 적합합니까? –

+0

원래 이름의 상점이 있어야합니다. – ChrisF

답변

11

은 여기

Response.AppendHeader("Content-Disposition","attachment; filename=LeftCorner.jpg"); 

string filename = "orignal file name.ext"; 
Response.AppendHeader("Content-Disposition","attachment; filename="+ filename +""); 

Downloading a File with a Save As Dialog in ASP.NET

+0

어떻게 자리를 차지할 다운로드가 무엇입니까? 나는 당신을 따르지 않을거야 ... –

+0

대답 –

+0

에 붙여 넣은 링크를 확인하면 모든 파일 형식 (.zip, rar, pdf 등)에서 작동합니까? –

1

브레 = 브레 델 기록 보관소 + 확장자 (ejemplo.txt)

public void DownloadFile(string ubicacion, string nombre) 
{ 
     Response.Clear(); 
     Response.ContentType = @"application\octet-stream"; 
     System.IO.FileInfo file = new System.IO.FileInfo(ubicacion); 
     Response.AddHeader("Content-Disposition", "attachment; filename=" + nombre); 
     Response.AddHeader("Content-Length", file.Length.ToString()); 
     Response.ContentType = "application/octet-stream"; 
     Response.WriteFile(file.FullName); 
     Response.Flush(); 
} 
+1

코드가하는 일을 설명하는 주석을 추가하십시오. 영어를 사용하십시오. 친애하는. – YakovL

관련 문제