zipuploadstreamprovider.vb
来自「大文件上传组件」· VB 代码 · 共 82 行
VB
82 行
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 + =
减小字号Ctrl + -
显示快捷键?