私の C# Web アプリケーションはC
ドライブ上にあります。ただし、アプリケーションはユーザーからアップロードされたドキュメントを受け取り、D
ドライブに保存します。
D
ドライブ上の Web アプリケーションの HyperLink コントロールの NavigateUrl プロパティで、ドライブ上のドキュメントへのパスを指定する方法を教えてくださいC
。
私の C# Web アプリケーションはC
ドライブ上にあります。ただし、アプリケーションはユーザーからアップロードされたドキュメントを受け取り、D
ドライブに保存します。
D
ドライブ上の Web アプリケーションの HyperLink コントロールの NavigateUrl プロパティで、ドライブ上のドキュメントへのパスを指定する方法を教えてくださいC
。
サーバー側では、ファイルをa内にロードし、Stream
このオブジェクトをとして応答できます。byte[]
public void Page_Load(object sender, System.EventArgs e)
{
// create a FileStream from a path from local (D:, C:, E:, etc...)
FileStream file = File.OpenRead(@"d:\folder\yourfile.txt");
//Convert the stream to an array of bytes.
byte[] byteArray = file.ToArray();
// Clear all content output from the buffer stream
Response.Clear();
// Add a HTTP header to the output stream that specifies the default filename
// for the browser's download dialog
Response.AddHeader("Content-Disposition", "attachment; filename=foo.txt");
// Add a HTTP header to the output stream that contains the
// content length(File Size). This lets the browser know how much data is being transfered
Response.AddHeader("Content-Length", byteArray.Length.ToString());
// Set the HTTP MIME type of the output stream
Response.ContentType = "application/octet-stream";
// Write the data out to the client.
Response.BinaryWrite(byteArray);
}