Hello Friends, I want to search a file in my computer and want to delete the file in VB.Net But I am getting delete a file when it's path is know, But I don't want to give the path. I want to give the path by searching it. If any one know it's solution then please Do reply. Thanks & Regards
So I googled for a second and found: For Each foundFile As String In My.Computer.FileSystem.GetFiles( _ My.Computer.FileSystem.SpecialDirectories.MyDocuments, _ FileIO.SearchOption.SearchAllSubDirectories, "*") My.Computer.FileSystem.DeleteFile(foundFile) Next Code (markup): This code will search your MyDocuments folder and all its sub-folders for all files and delete them. "*" is the pattern for ALL, you can use "*.txt" to file text files only or just "haha*" to delete any file that its name starts with "haha", no matter how it continues.
You could always try and mess with the folder permissions. Dim FolderPath As String = "C:\test\myfolder" Dim UserAccount As String = "domain1\testuser" Dim FolderInfo As IO.DirectoryInfo = New IO.DirectoryInfo(FolderPath) Dim FolderAcl As New DirectorySecurity FolderAcl = FolderInfo.GetAccessControl() FolderAcl.AddAccessRule(New FileSystemAccessRule(UserAccount, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)) FolderInfo.SetAccessControl(FolderAcl) Code (markup): Or change your test user for the app. File permissions can be a headache.
Just go to Project Settings -> Application Tab and click on the "View UAC Settings" or "View windows settngs" button. In the new tab opened, you will see a code like this, <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> <!-- UAC Manifest Options If you want to change the Windows User Account Control level replace the requestedExecutionLevel node with one of the following. <requestedExecutionLevel level="asInvoker" uiAccess="false" /> <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> <requestedExecutionLevel level="highestAvailable" uiAccess="false" /> Specifying requestedExecutionLevel node will disable file and registry virtualization. If you want to utilize File and Registry Virtualization for backward compatibility then delete the requestedExecutionLevel node. --> <requestedExecutionLevel level="highestAvailable" uiAccess="false" /> 'the line you need to paste it to </requestedPrivileges> Code (markup): from the comment copy any permssion you want and paste it before the ending requestedprivileges tag and delete the old lne there. This wll give you permissions to have admin rights and to change or delete folders from anywhere in the computer.