我对网站上的功能有疑问。
Private Sub AddToArchive(ByVal zip As Package, ByVal fileToAdd As String)
Try
'Replace spaces with an underscore (_)
Dim uriFileName As String = fileToAdd.Replace(" ", "_")
'A Uri always starts with a forward slash "/"
Dim zipUri As String = String.Concat("/", _
IO.Path.GetFileName(uriFileName))
Dim partUri As New Uri(zipUri, UriKind.Relative)
Dim contentType As String = _
Net.Mime.MediaTypeNames.Application.Zip
'The PackagePart contains the information:
' Where to extract the file when it's extracted (partUri)
' The type of content stream (MIME type): (contentType)
' The type of compression: (CompressionOption.Normal)
Dim pkgPart As PackagePart = zip.CreatePart(partUri, contentType, CompressionOption.Normal)
'Read all of the bytes from the file to add to the zip file
Dim bites As Byte() = File.ReadAllBytes(fileToAdd)
'Compress and write the bytes to the zip file
pkgPart.GetStream().Write(bites, 0, bites.Length)
Catch ex As Exception
sendException(computerUserName, "ZIP ITSELF EXCEPTION: " & ex.Message)
End Try
End Sub
当我有一个文件名如下的文件:näme.jpg时会抛出错误。
Part URI is not valid per rules defined in the Open Packaging Conventions specification.
为什么会发生这种情况?我该如何解决这个问题?