📄 zipuploadstreamprovider.vb
字号:
Imports System.IO
Imports ICSharpCode.SharpZipLib.Zip
Imports Krystalware.SlickUpload
Imports Krystalware.SlickUpload.Providers
''' <summary>
''' An <see cref="IUploadStreamProvider" /> that streams each file into its own .zip file.
''' </summary>
Public Class ZipUploadStreamProvider
Implements IUploadStreamProvider
Public Function GetInputStream(ByVal f As Krystalware.SlickUpload.UploadedFile) As System.IO.Stream Implements Krystalware.SlickUpload.Providers.IUploadStreamProvider.GetInputStream
Dim fileS As FileStream = Nothing
Dim zipS As ZipInputStream = Nothing
Try
Dim path As String = GetZipPath(f)
fileS = File.OpenRead(path)
zipS = New ZipInputStream(fileS)
zipS.GetNextEntry()
Return zipS
Catch
If Not fileS Is Nothing Then
fileS.Dispose()
End If
If Not zipS Is Nothing Then
zipS.Dispose()
End If
Return Nothing
end Try
End Function
Public Function GetOutputStream(ByVal f As Krystalware.SlickUpload.UploadedFile) As System.IO.Stream Implements Krystalware.SlickUpload.Providers.IUploadStreamProvider.GetOutputStream
Dim fileS As FileStream = Nothing
Dim zipS As ZipOutputStream = Nothing
Try
Dim outputPath As String = GetZipPath(f)
Directory.CreateDirectory(Path.GetDirectoryName(outputPath))
fileS = File.OpenWrite(outputPath)
zipS = New ZipOutputStream(fileS)
zipS.SetLevel(5)
zipS.PutNextEntry(New ZipEntry(f.ClientName))
Return zipS
Catch
If Not fileS Is Nothing Then
fileS.Dispose()
End If
If Not zipS Is Nothing Then
zipS.Dispose()
End If
Return Nothing
End Try
End Function
Public Sub RemoveOutput(ByVal f As Krystalware.SlickUpload.UploadedFile) Implements Krystalware.SlickUpload.Providers.IUploadStreamProvider.RemoveOutput
Dim path As String = GetZipPath(f)
If File.Exists(path) Then
File.Delete(path)
End If
End Sub
Private Function GetZipPath(ByVal file As UploadedFile) As String
Return Path.Combine(HttpContext.Current.Server.MapPath("~/Files/"), Path.GetFileNameWithoutExtension(file.ClientName) + ".zip")
End Function
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -