只想将此功能与特定文件扩展名(我定义)一起使用。我怎样才能在 ASP.net 中做到这一点?
基本上,以下代码允许下载任何文件,只需将文件指向此页面.aspx?file={path to file + file}
我想要做的是退出此页面,如果文件没有来自数组的扩展名这需要定义。例如:只希望能够通过以下代码下载以下扩展名:.jpg、.jpeg、.bmp、.png、.gif、.pdf、.doc、.docx
<%@ 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("Please provide a file to download.")
End If
End Sub
</script>
如何更改此功能以排除此功能处理所有文件扩展名,但列出的文件扩展名:.jpg、.jpeg、.bmp、.png、.gif、.pdf、.doc、.docx
我在想,这里需要在这一行 If file.Exists Then
中添加一些内容:需要更改为: If file.Exists AND file.Extension...