【发布时间】:2015-11-17 00:59:58
【问题描述】:
我正在创建一个按钮,当用户点击按钮时,我想压缩一个文件夹并下载它。
我的代码在本地主机上运行良好,但是当我将它移动到服务器时却出现错误。
这是错误:
Server Error in '/myapp' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
您将在下面找到我的 zip 和下载文件夹代码。我还添加了一个 system.io.compression 作为参考。
aspx.vb 代码:
Imports System.IO
Imports System.IO.Compression
' Inorder to use 'ZipFile', you first have to 'Add reference'
' Right Click project > Add Reference > Browse > "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.IO.Compression.FileSystem\..." > ok
Partial Class myclass
Inherits System.Web.UI.Page
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim folderPath As String = "C:\user\dave\desktop\MyFolder"
' Create Zip folder
Dim TempFile = System.IO.Path.GetTempFileName() + ".zip"
System.IO.Compression.ZipFile.CreateFromDirectory(folderPath, TempFile)
' Download Zip folder
Response.Buffer = False
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=Cases.zip")
Response.ContentType = "Application/zip"
Response.TransmitFile(TempFile)
Response.End()
End Sub
End Class
【问题讨论】: