Click here to Skip to main content
15,558,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used a small code snippet which belongs to a simple checklistbox file delete program. The original program works with the code but my program does not function the same and returns an exception as follows:

'The given path's format is not supported'.

the line of code that the exception happens to is:

Dim fileInfo As New FileInfo(item.ToString())

The source code Im trying to apply to my program is as follows:

Imports System.IO
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    For Each foundFile As String In My.Computer.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.Temp, FileIO.SearchOption.SearchAllSubDirectories, "*.*")            CheckedListBox1.Items.Add(foundFile)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        For Each item As Object In CheckedListBox1.CheckedItems
            If item.GetType() Is GetType(FileInfo) Then
            CType(item, FileInfo).Delete()

            ElseIf item.GetType() Is GetType(String) Then
                Dim fileInfo As New FileInfo(item.ToString())
                On Error Resume Next
            End If
        While CheckedListBox1.CheckedItems.Count > 0
        End While
    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            For i As Integer = 0 To CheckedListBox1.Items.Count - 1
                CheckedListBox1.SetItemChecked(i, True)
            For i As Integer = 0 To CheckedListBox1.Items.Count - 1
                CheckedListBox1.SetItemChecked(i, False)
        End If
    End Sub
End Class

The problem with this code is that I need the button3 click event (delete) to delete the file that is associated with the item found and not to load the file system special directories "*.*" My program is a scanner so it needs to be able to delete and remember the paths of the names it finds in my.resources.viruslist. Can anyone write this code to properly delete files that are found in the checklistbox items area?
Updated 10-Nov-10 16:38pm

What is the path that you are passing into item.

Debug and have a look at the path -
1) is the path valid?
2) do you have access to that path.

Remember, the paths for a program in debug mode and in "real" execution mode are always different.
Share this answer
Dale 2012 10-Nov-10 22:39pm    
I have made a virus scanner but need to be able to delete a checklistbox item and its file from my computer once a name matching a name in my text file has been found. Can you write a delete code that will do this for me?
It works on my computer. The error message says that you have an invalid file name while trying to create FileInfo object. Does it?
Share this answer
Dale 2012 10-Nov-10 22:37pm    
it says 'The given path's format is not supported' not that the name is invalid. why does this work for the original program but not for mine? all Id like is a delete code for a checklist box once an item is found. I have had many examples with no help really. Is it this hard once a file with a name is found to delete that item and file from your computer?
Heinzzy 10-Nov-10 22:56pm    
Debug your code and find out what is the exact path which cause the error.
Dale 2012 11-Nov-10 0:46am    
where can I see it?
Dale 2012 11-Nov-10 0:49am    
System.NotSupportedException was unhandled
Message=The given path's format is not supported.
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
at System.IO.FileInfo..ctor(String fileName)
at BlackOnyx_K2_Utilities_Professional_2010.Antivirus.Button3_Click(Object sender, EventArgs e) in C:\Users\Draco\Documents\Visual Studio 2010\Projects\BlackOnyx K2 Utilities Professional 2010\BlackOnyx K2 Utilities Professional 2010\Antivirus.vb:line 313
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at BlackOnyx_K2_Utilities_Professional_2010.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at System.Activator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Dale 2012 11-Nov-10 0:49am    
does this tell you what I need to do?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900