단순히 서버에 다시 게시하고 다음 메소드를 호출하는 LinkButton을 사용할 수 있습니까?
internal static void ContentToBrowser(string contentType, string filename, string content)
// Send to browser
var response = HttpContext.Current.Response;
response.Clear();
response.ContentType = contentType;
response.AddHeader("Content-Disposition",
String.Format("attachment; filename=\"{0}\"", filename));
var contentLength = response.ContentEncoding.GetByteCount(content);
response.AddHeader("Content-Length", contentLength.ToString());
response.Write(content);
response.End();
}
이렇게하면 서버에 저장하는 것에 대해 걱정할 필요없이 필요한 콘텐츠를 클라이언트에 바로 쓸 수 있습니다. 예 :
protected void LinkButtonClick(object sender, EventArgs e)
{
string filename = @"c:\filepath\blah.xlsx";
string content = File.ReadAllText(filename);
ContentToBrowser("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "downloaded-blah.xlsx", content);
File.Delete(filename);
}
그러나 나중에 파일을 삭제할 동기가 무엇인지 질문해야합니다. 클라이언트가 성공적으로 다운로드하여 저장했음을 어떻게 알 수 있습니까?
링크가 정확한 형식과 일치해야합니까? 이게 효과가 있니? http://formvalue.co.za/download?file=whatever.xlsx – Nuzzolilo
무엇을할까요?/할 대신에? – Pomster
그 자체로는 아무 것도 없습니다. 직접적인 질문이었습니다 ... – Nuzzolilo