在vb.net 2008中解压缩文件时出错 [英] Error while Unzipping file in vb.net 2008
本文介绍了在vb.net 2008中解压缩文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个将文件解压缩并放置到给定路径中的表格
这是我的代码:
I have a form to unzipping file and place into given path
Here is my code :
Imports System.IO
Imports System.Windows.Forms
Imports System.Data
Imports Shell32
Private Sub btnbrow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbrow.Click
OpenFileDialog1.InitialDirectory = "D:\TempUZip"
OpenFileDialog1.Filter = "Zip Files (*.zip)|*.zip"
OpenFileDialog1.FilterIndex = 2
OpenFileDialog1.RestoreDirectory = True
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
txtfn.Text = OpenFileDialog1.FileName
End If
End Sub
Sub UnZip()
Dim fn As String
fn = txtfn.Text
Dim sc As New Shell32.Shell()
'Declare the folder where the files will be extracted
Dim output As Shell32.Folder = sc.NameSpace("D:\TempImp")
'Declare your input zip file as folder .
Dim input As Shell32.Folder = sc.NameSpace(" " & fn & " ")
'Extract the files from the zip file using the CopyHere command .
output.CopyHere(input.Items, 4)
End Sub
当我运行表格
我收到错误消息:
对象引用未设置为对象的实例.
空引用异常已解除阻止
任何帮助将不胜感激.
在此先感谢...
When i run the form
I get error :
Object reference not set to an instance of an object.
Null Reference exception was unhalndled
Any Help will be highly appreciated.
Thanks in Advance...
推荐答案
我正在猜测(因为您没有告诉我们哪一行引发了错误),但是我怀疑您没有尚未创建OpenFileDialog的实例,因此当您尝试设置InitialDirectory属性时发生错误.
尝试添加:
在btnbrow_Click
例程开始时,
I''m guessing (because you don''t tell us which line throws the error), but I suspect that you haven''t created an instance of the OpenFileDialog, so the error occurs when you try to set the InitialDirectory property.
Try adding:
OpenFileDialog1 = New OpenFileDialog()
.
如果不是,请尝试在调试器中查找确实会导致错误的行-要么很明显的一部分是nothing
/null
,要么您可以告诉我们它在哪一行是...
at the start of your btnbrow_Click
routine.
If it isn''t that, then try looking in the debugger at the line which does cause the error - either it will be obvious that one of the parts is nothing
/ null
, or you can tell us which line it is...
这篇关于在vb.net 2008中解压缩文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文