いくつかのドキュメントを格納する SQL データベースがあります。
ユーザーはアプリケーションにサインインして、ドキュメントのリストを表示できます。
ドキュメントのグリッドビューでリンクボタンのダウンロードをクリックすると、データベースからファイルを取得し、ファイル システムに書き込み、このコードを実行します。
System.IO.FileInfo file = new System.IO.FileInfo(System.Configuration.ConfigurationManager.AppSettings["UploadPath"] + DocumentName);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.Cookies.Clear();
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.CacheControl = "private";
Response.Charset = System.Text.UTF8Encoding.UTF8.WebName;
Response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
Response.AppendHeader("Content-Length", file.Length.ToString());
Response.AppendHeader("Pragma","cache");
Response.AppendHeader("Expires", "60");
Response.ContentType = GetContentType(file.Extension);
Response.AppendHeader("Content-Disposition",
"inline; " +
"filename=\"" + file.Name + "\"; " +
"size=" + file.Length.ToString() + "; " +
"creation-date=" + DateTime.Now.ToString("R") + "; " +
"modification-date=" + DateTime.Now.ToString("R") + "; " +
"read-date=" + DateTime.Now.ToString("R"));
私の GetContentType() メソッドは、「application/pdf、application/msw0rd など」を許可しているファイルの適切なファイル タイプを返すだけです。
私の問題は、ファイルが保存されると、ファイル システムのファイルではなく、Web ページ自体になることです。Google Chrome では、ファイル名の末尾に .htm 拡張子を付けていますが、これは Web ページであることを認識しているためでしょうか?
とにかく、最初のステップとしては、実際のファイルを取得することです。HTML の Web ページのコピーではありません。
ありがとう。