扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
Aspnet_wp.exe(对于在 Microsoft Internet 信息服务 [IIS] 6.0 上运行的应用程序,则为 W3wp.exe)意外停止。
在此过程中,您还可能会发现 Web 服务器的内存使用量增加。| 回到顶端 |
| 回到顶端 |
Dim iStream As System.IO.Stream
' Buffer to read 10K bytes in chunk:
Dim buffer(10000) As Byte
' Length of the file:
Dim length As Integer
' Total bytes to read:
Dim dataToRead As Long
' Identify the file to download including its path.
Dim filepath As String = "DownloadFileName"
' Identify the file name.
Dim filename As String = System.IO.Path.GetFileName(filepath)
Try
' Open the file.
iStream = New System.IO.FileStream(filepath, System.IO.FileMode.Open, _
IO.FileAccess.Read, IO.FileShare.Read)
' Total bytes to read:
dataToRead = iStream.Length
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment; filename=" & filename)
' Read the bytes.
While dataToRead > 0
' Verify that the client is connected.
If Response.IsClientConnected Then
' Read the data in buffer
length = iStream.Read(buffer, 0, 10000)
' Write the data to the current output stream.
Response.OutputStream.Write(buffer, 0, length)
' Flush the data to the HTML output.
Response.Flush()
ReDim buffer(10000) ' Clear the buffer
dataToRead = dataToRead - length
Else
'prevent infinite loop if user disconnects
dataToRead = -1
End If
End While
Catch ex As Exception
' Trap the error, if any.
Response.Write("Error : " & ex.Message)
Finally
If IsNothing(iStream) = False Then
' Close the file.
iStream.Close()
End If
End Try
Visual C# .NET 代码System.IO.Stream iStream = null;
// Buffer to read 10K bytes in chunk:
byte[] buffer = new Byte[10000];
// Length of the file:
int length;
// Total bytes to read:
long dataToRead;
// Identify the file to download including its path.
string filepath = "DownloadFileName";
// Identify the file name.
string filename = System.IO.Path.GetFileName(filepath);
try
{
// Open the file.
iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open,
System.IO.FileAccess.Read,System.IO.FileShare.Read);
// Total bytes to read:
dataToRead = iStream.Length;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
// Read the bytes.
while (dataToRead > 0)
{
// Verify that the client is connected.
if (Response.IsClientConnected)
{
// Read the data in buffer.
length = iStream.Read(buffer, 0, 10000);
// Write the data to the current output stream.
Response.OutputStream.Write(buffer, 0, length);
// Flush the data to the HTML output.
Response.Flush();
buffer= new Byte[10000];
dataToRead = dataToRead - length;
}
else
{
//prevent infinite loop if user disconnects
dataToRead = -1;
}
}
}
catch (Exception ex)
{
// Trap the error, if any.
Response.Write("Error : " + ex.Message);
}
finally
{
if (iStream != null)
{
//Close the file.
iStream.Close();
}
}
将 DownloadFileName 替换为大于 100 MB 的文件的名称。| • | 为用户提供用于下载文件的链接。 - 或 - |
| • | 使用 Microsoft ASP 3.0 进行下载或者与 ASP 一起使用 Software Artisans FileUp。 - 或 - |
| • | 创建 ISAPI 扩展以下载文件。 - 或 - |
| • | 使用 FTP 下载文件。 |
| 回到顶端 |
| 回到顶端 |
| 1. | 在 Microsoft Visual Basic .NET 或 Microsoft Visual C# .NET 中,新建一个 Web 应用程序项目。默认情况下,将创建 WebForm1.aspx。 |
| 2. | 将一个按钮对象从工具箱拖到 WebForm1.aspx。 |
| 3. | 双击该按钮对象以便在代码视图中打开 click 事件。 |
| 4. | 将以下代码粘贴到 Button1 click 事件中。 visual Basic .NET 代码 ' Identify the file to download including its path.
Dim filepath As String = DownloadFileName
' Identify the file name.
Dim filename As String = System.IO.Path.GetFileName(filepath)
Response.Clear()
' Specify the Type of the downloadable file.
Response.ContentType = "application/octet-stream"
' Set the Default file name in the FileDownload dialog box.
Response.AddHeader("Content-Disposition", "attachment; filename=""" & filename & """")
Response.Flush()
' Download the file.
Response.WriteFile(filepath)Visual C# .NET 代码 // Identify the file to download including its path.
string filepath = DownloadFileName;
// Identify the file name.
string filename = System.IO.Path.GetFileName(filepath);
Response.Clear();
// Specify the Type of the downloadable file.
Response.ContentType = "application/octet-stream";
// Set the Default file name in the FileDownload dialog box.
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
Response.Flush();
// Download the file.
Response.WriteFile(filepath); |
| 5. | 将 DownloadFileName 替换为大于 100 MB 的文件的名称。 |
| 6. | 在“调试”菜单上,单击“开始”。 |
| 7. | 单击“Button1” |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。