步骤
- 首先,我们只需创建一个新的ASP.NET Web应用程序。
- 现在在解决方案资源管理器中右键单击项目,然后单击"添加新文件夹"。将将文件夹添加到项目中。将名称图像镜像到文件夹。现在,我们要在此文件夹中下载复制和粘贴的任何文件,因为我添加了名为(statemanagement.ppt)的文件。
- 在代码链接标记中指定文件夹名称和文件名。
- 现在在default.aspx中写下以下代码。
<a href="images/StateManagement.ppt">Download the file</a> <%@ Page language="vb" runat="server" explicit="true" strict="true" %> <script language="vb" runat="server"> Sub Page_Load(Sender As Object, E As EventArgs) Dim strRequest As String = Request.QueryString("file") If strRequest <> "" Then Dim path As String = Server.MapPath(strRequest) Dim file As System.IO.FileInfo = New System.IO.FileInfo(path) If file.Exists Then Response.Clear() Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name) Response.AddHeader("Content-Length", file.Length.ToString()) Response.ContentType = "application/octet-stream" Response.WriteFile(file.FullName) Response.End Else Response.Write("This file does not exist.") End If Else Response.Write("Click link to download.") End If End Sub </script>
- 现在运行应用程序。
在使用流中,我们可以为用户提供文件,无需FTP或者Internet信息服务器(IIS)的任何干扰,当我们将创建Web应用程序时,我们还将文件夹添加到包含该文件的应用程序中你想下载。
日期:2020-04-11 22:50:12 来源:oir作者:oir