Я пытаюсь разработать код для распаковки файла из zip-файла в Silverlight 5. Файлы находятся в каталоге в zip-файле.Unzip zip-файл в silverlight
Я перевел этот код, который я нашел в другом месте от C# до VB, так как мы являемся магазином VB. Он не работает в четвертой строке «Ссылка на объект не установлена в экземпляр объекта». Теперь я понимаю, что проблема в том, что третья строка ожидает относительного uri, и я передаю ему файл, но я не знаю, как это исправить.
Не могли бы вы рассказать мне, что не так с этим кодом. Я также буду приветствовать другие идеи.
Спасибо.
Public Shared Function GetZipContents(ByVal filename As String) As String()
Try
Dim zipStream As System.IO.Stream = New System.IO.MemoryStream()
Dim zipInfo As New StreamResourceInfo(zipStream, Nothing)
Dim streamInfo As StreamResourceInfo = Application.GetResourceStream(zipInfo, New Uri(filename, UriKind.Relative))
Dim fileStream As Stream = streamInfo.Stream
Dim names As New List(Of String)()
Dim reader As New BinaryReader(fileStream)
Do While reader.ReadUInt32() = &H4034B50
' Skip the portions of the header we don't care about
reader.BaseStream.Seek(14, SeekOrigin.Current)
Dim compressedSize As UInteger = reader.ReadUInt32()
Dim uncompressedSize As UInteger = reader.ReadUInt32()
Dim nameLength As Integer = reader.ReadUInt16()
Dim extraLength As Integer = reader.ReadUInt16()
Dim nameBytes() As Byte = reader.ReadBytes(nameLength)
names.Add(Encoding.UTF8.GetString(nameBytes, 0, nameLength))
reader.BaseStream.Seek(extraLength + compressedSize, SeekOrigin.Current)
Loop
' Move the stream back to the begining
fileStream.Seek(0, SeekOrigin.Begin)
Return names.ToArray()
Catch ex As Exception
MessageBox.Show(ex.Message)
Return Nothing
End Try
End Function