从计算机删除项目和文件 [英] Delete Items And Files From Computer
问题描述
我正在使用列表视图框显示在文本文件(my.resources.viruslist.text)中找到的项目名称.我的问题是,删除文件后,删除代码不会从计算机中删除该项目或文件.在我的文本文件中找到与名称匹配的内容.
我现在拥有的代码是:
I am using a listview box to display item names that are found within my text file (my.resources.viruslist.text) My problem is that the delete code does not remove the item or file from my computer once the file is found matching the name in my text file.
The code I have now is:
Private Sub ButtonDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDelete.Click
If ListViewFiles.CheckedIndices.Count >0 Then
If MessageBox.Show("Delete" + ListViewFiles.CheckedIndices.Count.ToString + "file(s)?", "Delete Files", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
For Each item In ListViewFiles.CheckedIndices
Try
File.Delete(ListViewFiles.Items(item))
Catch ex As Exception
MsgBox("Error deleting file: " + ex.Message)
End Try
Next
End If
End If
End Sub
另外,当我在加载程序时按Delete键时,会出现异常:
错误删除文件:从"ListViewItem"类型到"String"类型的转换无效
我试图通过在删除代码中添加断点来隔离问题,但是我看到的唯一建议是:
{Text =删除感染"}
如果有人可以提供详细的修订工作代码,那将是最有帮助的.如果在代码示例中使用变量,请提供您对该变量的引用.
预先感谢您有美好的一天:) !! ........
Also When I hit delete when the program is loaded I get the exception:
"Error deleting file: Conversion from type ''ListViewItem'' to type ''String'' is not valid
I have tried to isolate the problem by adding a breakpoint to the delete code but the only suggestion I can see is:
{Text = "Delete Infections"}
It would be most helpfull if someone can provide a revised working code in full detail. If you use variables in your code example please provide the reference you are giving to the variable.
Thank you in advance have a nice day :) !!.......
推荐答案
Try:
Try:
File.Delete(ListViewFiles.Items(item).Text)
[edit]糟糕-将C#与VB混合... [/edit]
[edit]Whoops - mixing C# in with VB...[/edit]
这篇关于从计算机删除项目和文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!