Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用vb.net在服务器上压缩文件夹?_.net_Vb.net_Zip_Directory - Fatal编程技术网

如何使用vb.net在服务器上压缩文件夹?

如何使用vb.net在服务器上压缩文件夹?,.net,vb.net,zip,directory,.net,Vb.net,Zip,Directory,我正在创建一个按钮,当用户点击按钮时,我想压缩一个文件夹并下载它 我的代码在本地主机上运行得很好,但当我将其移动到服务器时,会出现错误 错误如下: Server Error in '/myapp' Application. Runtime Error Description: An application error occurred on the server. The current custom error settings for this application prevent th

我正在创建一个按钮,当用户点击按钮时,我想压缩一个文件夹并下载它

我的代码在本地主机上运行得很好,但当我将其移动到服务器时,会出现错误

错误如下:

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>
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

您似乎已硬编码文件夹路径:

Dim folderPath As String = "C:\user\dave\desktop\MyFolder"
下面是一些你可以检查的东西:

  • 此文件夹实际上存在于部署应用程序的服务器上
  • 应用程序池运行时使用的标识具有对此文件夹的读取权限
要查明问题,您只需按照错误消息中的建议并在web.config中启用详细的错误输出:

<system.web>
    <customErrors mode="Off" />
</system.web>

您似乎对文件夹路径进行了硬编码:

Dim folderPath As String = "C:\user\dave\desktop\MyFolder"
下面是一些你可以检查的东西:

  • 此文件夹实际上存在于部署应用程序的服务器上
  • 应用程序池运行时使用的标识具有对此文件夹的读取权限
要查明问题,您只需按照错误消息中的建议并在web.config中启用详细的错误输出:

<system.web>
    <customErrors mode="Off" />
</system.web>