How to hide root folders & files in dialog box vb.net - vb.net

basically I am making trying to make a folder dialog box, to which if we give a root path it shows me that specific folder and its sub directories and files i don't want the unnecessary folders e.g parent folders of that root folder to appear for this am trying to make a custom(user) folder dialog box control. but still am unsure how to hide the parent folders.
My control in which i give root path: My control output Picture here
In the above picture i dont want to see the unnecessary folders existing above.
I want something like this
I am really confused how to do it ?

Yet there is no way to select custom root folder. Perhaps, you can use custom selected path to navigate directly to your directory before calling dialogue.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FolderBrowserDialog1.SelectedPath = "Your Directory Path"
FolderBrowserDialog1.ShowDialog()
TextBox1.Text = FolderBrowserDialog1.SelectedPath
End Sub

Related

Create folder in Windows CE

I am working on an old application running on a Windows CE device. This is old software that is still in use.
As of now, they need to create the folder on the flash drive (there are no drive letters). My idea was to create the folder if missing. However, it gives an error when creating the directory.
The folder is used to save data for later use.
Any ideas on how create a folder from SW?
Here is my VB code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Directory.Exists("QuaData") Then
Directory.CreateDirectory("QuaData")
End If

Exception thrown on bitmap declaration under weird circumstances

I encountered this problem and through much frustration isolated it to this.
When I drag a file on my exe from another folder, a bitmap declaration that has nothing to with the command line arguments throws an exception "System.ArgumentException: Parameter is not valid".
This does not happen when:
The file is dragged from the same folder as exe
The file is dragged on a shortcut of the exe
Here is the minimum code that produces this error:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim logo As New Bitmap("logo.png") 'an image in the same dir as exe
Me.BackgroundImage = logo
Catch ex As Exception
MessageBox.Show("Exception: " & ex.Message)
End Try
End Sub
End Class
If you provide just a file name then it is assumed that that file resides in the current directory. The current directory is not always the same at startup and it can change while an application is running too.
I'm guessing that that file is in the same folder as your EXE. In that case, when the code works the current directory must be the application folder and in cases where it fails the current directory must be some other folder.
We often see similar issues when Process.Start is used run a game. Many games do as you have and assume that the current directory is the application folder. If you run the game from the commandline or the like then it will be. If you use Process.Start to run the game from code, the new process will actually inherit the current directory of your application and that sort of code will fail.
The solution is to ALWAYS be explicit about the path of a file. If you want to open a file that is in your application folder then specify exactly that:
Dim logo As New Bitmap(IO.Path.Combine(Application.StartupPath, "logo.png"))
That code doesn't rely on the current directory being a specific folder so will be unaffected if it isn't.

Delete relative path in Visual Basic

I'm essentially trying to figure out a simple method for deleting a relative path in vb. I want a user to be able to run the program and delete a specific folder within the AppData/Local folder on Windows. The purpose of the program is to remove Google Chrome user data when the user is finished with their session. I'm running in to trouble with:
My.Computer.FileSystem.DeleteDirectory
I'm trying to use this method to remove all folders within the \Google folder. The problem is, that since the \Google folder is relative, if anybody besides me tries to use it, it simply wont work since I would use: My.Computer.FileSystem.DeleteDirectory("C:\Users\Erik\AppData\Local\Google", FileIO.DeleteDirectoryOption.DeleteAllContents). How can I modify this program to remove the \Google folder under whichever user profile the program happens to be executed under?
You can do this with the Environent Paths:
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\Google")
End Sub
End Class
This gets the Local Appdata Path for the current User.

Linking to internal html pages with LinkLabel

Visual Basic:
Trying to get my VB program to run an internal HTML file without it needing to navigate back the the C: drive.
Using:
Private Sub frmMalphite_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LinkLabel1.Links.Add(6, 4, "C:\Users\User\Desktop\Test\Test1\Test2.html")
End Sub
Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
System.Diagnostics.Process.Start(e.Link.LinkData.ToString())
End Sub
I can get the html page to run, however it would not work if I opened the project on another computer, because the absolute path given. Looking for a work around so I don't have to change the path on every computer I use to work on the project.
If the file exists on a drive on MachineA, then the only way you can open this from MachineB is to put the file on a shared drive and access the file via this share.
This will work from any machine that has permissions to read that share.
Something like:
LinkLabel1.Links.Add(6, 4, "\\MachineA\SharedDrive\Test2.html")
You may have access to the hidden administrative share on MachineA (\\MachineA\c$) from MachineB but you can't rely on it.

Compile or Export a Coded Form

How can i export or compile a form that i make with code within a running application in VB.NET?
I'm making a simple form making application, i've got almost everything covered, with creating the new form and adding controls and stuff.
Example: create a new form with clicking a button:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim NewForm As New Form
NewForm.Name = "Form1"
NewForm.Text = "Form1"
NewForm.Width = 300
NewForm.Height = 300
NewForm.Show()
End Sub
How do i export or compile the new form to a standalone exe?
Any help is greatly appreciated.
Create your own file format (XML?) that describes the contents of the form.
Then, create a separate application that reads these files and display a form based on the file that it read.
If you want to ship single EXEs, you could embed the file as a resource in the launcher application and modify that resource to save custom EXEs.
Alternatively, you could use Roslyn or Mono Cecil or Expression trees to actually compile that code at runtime into a new EXE; that may be harder.