0
A
回答
1
您不能在傳統的asp中使用任何這些庫。一種方法是嘗試使用regasm.exe實用程序將它們註冊爲COM組件,但我不確定這些程序集是否標有COMVisible屬性。
1
您將需要爲選定的.NET庫創建COM wrapper。
然後,您將能夠引用傳統ASP中的包裝並使用它。
1
與某些看法相反,很容易在COM環境中使用DotNetZip,包括ASP。
DotNetZip包含的示例顯示了從VBScript和Javascript創建zip文件。 您可以輕鬆地調整此代碼以使用ASP classic。
在ASP經典頁面中讀取ZIP文件的源代碼中也有一個示例。它看起來像這樣:
<%@ LANGUAGE = VBScript %>
<% Option Explicit %>
<%
' -------------------------------------------------------
' ASP DotNetZip Example
' -------------------------------------------------------
' This example ASP page uses DotNetZip (Ionic.Zip.dll) via COM
' interop. The page opens a zip file, then allows the user
' to download any individual file within the zip file.
'
'' To get this to work, you must be sure to register DotNetZip for COM
'' interop (regasm). Also you need to be sure that IIS/ASP has the correct
'' permissions to instantiate the ZipFile object. In my experience I Was
'' able to do this by copying Ionic.Zip.dll to the
'' c:\windows\system32\inetsrv directory, then calling "regasm /codebbase
'' Ionic.Zip.dll" from within that directory.
'' This example assumes that the ASP page is deployed into a directory,
'' that contains a subdirectory called "fodder". Fodder must be readable,
'' and should contain one or more zip files. This page allows the user to
'' select a zip file, then select a file within the zip file, and download
'' that file.
''
If Request.Form("Submit") = "Download" Then
dim pathForZipFile, fileToDownload
pathForZipFile= Request.Form("zipFile")
if pathForZipFile <> "" Then
fileToDownload = Request.Form("fileToDownload")
Response.Clear
Response.AddHeader "Content-Disposition", "attachment; filename=" & fileToDownload
Response.ContentType = "application/octet-stream"
pathForZipFile = Server.MapPath("fodder\" & pathForZipFile)
dim zip, ms
set zip = Server.CreateObject("Ionic.Zip.ZipFile")
zip.Initialize(pathForZipFile)
set ms = Server.CreateObject("System.IO.MemoryStream")
dim selectedEntry, entry
For Each entry in zip
If entry.FileName = fileToDownload Then
set selectedEntry = entry
End If
Next
selectedEntry.Extract_3(ms)
zip.Dispose
dim fred
fred = ms.ToArray
Response.BinaryWrite(fred)
ms.Dispose
End If
Else
%>
<html>
<HEAD>
<TITLE>Simple DotNetZip Example</TITLE>
<style>
BODY { font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 10pt;}
TD { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt;}
TH { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt;}
H2 { font-size: 16pt; font-weight: bold; font-family: Verdana, Arial, Helvetica, sans-serif; color:Navy;}
H1 { font-size: 20pt; font-weight: bold; font-family: Verdana, Arial, Helvetica, sans-serif; color:Blue;}
</style>
<script language="Javascript">
function Download(file, zipFile)
{
document.form1.fileToDownload.value = file;
document.form1.zipFile.value = zipFile;
document.form1.submit();
}
</script>
<script RUNAT=Server language="VBScript">
'-------------------------------------
' This reads the given zip file.
'-------------------------------------
Sub DisplayContentsOfZip
dim pathForZipFile
pathForZipFile= Request.Form("selectedZip")
if pathForZipFile <> "" Then
pathForZipFile = Server.MapPath("fodder\" & pathForZipFile)
dim zip
set zip = Server.CreateObject("Ionic.Zip.ZipFile")
zip.Initialize(pathForZipFile)
response.write "<table border=1><tr><th>Name</th><th>last modified</th></tr>"
dim entry, fN
For Each entry in zip
If Right(entry.FileName,1) <> "/" Then
Response.Write "<tr><TD><input type='submit' name='Submit' value='Download' onClick=" & chr(34) & "Download('" & _
entry.FileName & "', '" & Request.Form("selectedZip") & "');" & chr(34) & " ></TD><td>" & _
entry.FileName & "</td><td>" & entry.LastModified & "</td></tr>"
End If
Next
response.write "</table>"
zip.Dispose()
End If
End Sub
'-------------------------------------
' This function builds and returns the
' option list for the form. eg:
' <OPTION value="file1.zip">file1.zip</OPTION>
' <OPTION value="file2.zip">file2.zip</OPTION>
' <OPTION value="file3.zip">file3.zip</OPTION>
'-------------------------------------
Function FileList()
Dim fso, folder, ext, item, result
result = ""
Set fso= Server.CreateObject("Scripting.FileSystemObject")
Set folder = FSO.GetFolder(Server.MapPath("fodder"))
For Each item In folder.Files
ext = Right(item.Name,4)
If (ext = ".zip") Then
result = result & "<OPTION value='" & item.Name & "'>" & item.Name & "</OPTION>"
End If
Next
Set fso = Nothing
Set folder = Nothing
FileList = result
End Function
</script>
</HEAD>
<body>
<h1>ASP DotNetZip</h1>
<p> This page shows how to use <a
href="http://DotNetZip.codeplex.com">DotNetZip</a> from an ASP (Classic)
page. This page reads zip files and allows the browser to download
items from the zip files. </p>
<form METHOD="POST" id='form1' name='form1'>
<TABLE style="border:1; cellspacing:1; cellpadding:1;">
<TR> <TD>Select a Zip file:</TD>
<TD><SELECT id='select1' name='selectedZip'>
<%= fileList %>
</SELECT>
</TD>
</TR>
<TR> <TD/><TD><input type='submit' name="Submit" Value="Read Zip"/></TD> </TR>
</TABLE>
<input type="hidden" name="fileToDownload" value="">
<input type="hidden" name="zipFile" value="">
<%
DisplayContentsOfZip
%>
</form>
</body>
</html>
<%
End If
%>
要查看最新版本的例子,去http://dotnetzip.codeplex.com/SourceControl/list/changesets,然後點擊「瀏覽」,然後展開名爲「實例」的目錄。
相關問題
- 1. C#OutOfMemoryException使用SharpZipLib創建ZipOutputStream
- 2. 使用SharpZipLib創建Zip文件
- 3. 使用VB.NET和DotNetZip或IonicZip庫創建自解壓文件
- 4. 用DotNetZip創建C#線程文件
- 5. SharpZipLib Deflater創建錯誤的數據
- 6. 使用SharpZipLib創建一個沒有文件夾結構的.tar.gz壓縮包使用SharpZipLib
- 7. 使用dotnetzip
- 8. DotNetZip庫:創建拆分檔案 - System.UnauthorizedAccessException
- 9. DotNetZip創建損壞的存檔(壞CRC)
- 10. DotNetZip:使用C#權限問題創建zip
- 11. 如何使用DotNetZip
- 12. 使用BZip2(SharpZipLib)的OutOfMemoryException
- 13. 在PowerShell中使用DotNetZip
- 14. 使用DotNetZip時出錯
- 15. DotNetZip真的使用WinZipAes256嗎?
- 16. 使用dotnetzip列出文件
- 17. SharpZipLib使用內存字符串創建存檔並作爲附件下載
- 18. 如何在C#中使用SharpZipLib創建超過7 GB的zip文件?
- 19. C#SharpZipLib
- 20. SharpZipLib GetInputStream
- 21. 使用DotNetZip創建Zip文件時出錯:意外的存檔結束
- 22. 無法刪除創建者SharpZipLib(FastZip)Zip文件
- 23. 如何在Monotouch中使用sharpziplib?
- 24. 使用SharpZipLib解壓縮特定文件?
- 25. 24GB tar.gz使用sharpziplib解壓縮
- 26. 使用SharpZipLib並獲取進度狀態?
- 27. C++和SharpZipLib
- 28. SharpZipLib - 提取
- 29. 帶MemoryStream的SharpZipLib
- 30. DotNetZip:將文件添加到動態創建的存檔目錄
@Steven。感謝: - ((我在ASP.Net 4.0工作,但不知何故,我必須在這個應用程序上做一些工作 – MUS 2010-08-20 09:45:54