How to register an icon to a file association? - vb.net

There are two file extentions called .luo and .luda.
When the program loads the .luo and .luda are assigned.
The variables path and path2 contains the location to the icons.
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim path, path2 As String
path = Application.StartupPath & "ludafile.ico"
path2 = Application.StartupPath & "luofile.ico"
My.Computer.Registry.ClassesRoot.CreateSubKey(".luda").SetValue("", "Luda Solution (.luda)", Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.ClassesRoot.CreateSubKey(".luo").SetValue("", "Luda Page File (.luo)", Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.ClassesRoot.CreateSubKey("LudaCreate\shell\open\command").SetValue("", Application.ExecutablePath & " ""%l"" ", Microsoft.Win32.RegistryValueKind.String)
End Sub
The code above succesfully works but I want to register an icon to these files.
One icon for .luda and another for .luo.

Related

Crystal Report Load Report Failed vb.net

I have an Error in Load report Failed.
This is my code :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CrystalReportViewer1.ReportSource = Application.StartupPath + "C:\Users\user\Desktop\Lastnato\IT58 PROJECTS\BRCPS\SoftEng ProjSystem\Reports\CrystalReport1.rpt"
CrystalReportViewer1.SelectionFormula = "{Lastname} = '" & TextBox1.Text.ToString & "' "
CrystalReportViewer1.RefreshReport()
CrystalReportViewer1.Refresh()
End Sub
can you please help me.
You probably don't want to use Application.StartupPath and a path that starts like: "c:\Users". Probably your Application Startup Path is already like "C:\Users\user\Desktop\Lastnato\IT58 PROJECTS\BRCPS\SoftEng ProjSystem"
If your reports are in the same folder as your .exe file, you probably want this line instead
'Not this (original)
'CrystalReportViewer1.ReportSource = Application.StartupPath + "C:\Users\user\Desktop\Lastnato\IT58 PROJECTS\BRCPS\SoftEng ProjSystem\Reports\CrystalReport1.rpt"
'Which would end up looking like:
' "C:\Users\user\Desktop\Lastnato\IT58 PROJECTS\BRCPS\SoftEng ProjSystemC:\Users\user\Desktop\Lastnato\IT58 PROJECTS\BRCPS\SoftEng ProjSystem\Reports\CrystalReport1.rpt"
'Instead, just use the relative path
CrystalReportViewer1.ReportSource = Path.Combine(Application.StartupPath, "Reports\CrystalReport1.rpt")
Also, I recommend using Path.Combine() because it easily takes care of putting one backslash (not two or zero) when it combines.

How to write a text file to a desktop sub-folder in vb.net

Please I want to write a text file to a sub-folder I have created within a folder on the desktop i.e.
Desktop Folder > Sub-folder > Text file
The code I came up with is shown below. I have created the sub-folder within the parent desktop folder, but cannot locate this sub-folder to write and save the text file. Please I would appreciate any suggestions. I am using Visual Basic 2010 Express. Thank you in advance.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
‘Check if a sub-folder with the title specified in Textbox1 does not exist in desktop folder titled Family
If (Not System.IO.Directory.Exists("C:\Users\" & Environ("username") & "\Desktop\Family\" & TextBox1.Text)) Then
‘Create a sub-folder within desktop folder titled Family with the title specified in Textbox1
System.IO.Directory.CreateDirectory("C:\Users\" & Environ("username") & "\Desktop\Family\" & TextBox1.Text)
End If
Dim fileTXT As New IO.StreamWriter("C:\Users\" & Environ("username") & "\Desktop\Family\" & TextBox1.Text & TextBox1.Text & ".TXT")
fileTXT.Write(TextBox2.Text)
fileTXT.WriteLine("")
Close()
End Sub
I would write your code this way:
Dim di = New DirectoryInfo(Path.Combine( _
Environment.GetFolderPath(Environment.SpecialFolder.Desktop), _
"Family\" & TextBox1.Text))
If Not di.Exists
di.Create()
End If
Dim fn = Path.Combine(di.FullName, TextBox1.Text + ".TXT")
File.WriteAllText(fn, TextBox2.Text + Environment.NewLine)
Try this to get the desktop folder:
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
You can then use System.IO.Path.Combine to add the Family subfolder. Make sure that subfolder exists before creating any folders underneath it.

Opening an Empty Directory from a Windows Form - VB.net

I'm trying to open a directory via my Windows Form created in VB.Net but every solution I've found doesn't seem to work.
Currently I'm using-
Dim path As String = Directory.GetCurrentDirectory()
Private Sub logDirBTN_Click(sender As Object, e As EventArgs) Handles logDirBTN.Click
Process.Start(path + "\Resources\Logs")
End Sub
Which returns "The system cannot find the file specified" exception. That's interesting because I know the folder is there. Furthermore this button's functionality works without any issue and from what I can tell the only difference is I'm opening a text file rather than an empty directory-
Private Sub stationListBTN_Click(sender As Object, e As EventArgs) Handles stationListBTN.Click
Process.Start("notepad.exe", path + "\Resources\StationList\StationList.txt")
End Sub
Here are all the other things I've tried-
Private Sub logDirBTN_Click(sender As Object, e As EventArgs) Handles logDirBTN.Click
'Process.Start("explorer.exe", path + "\Resources\Logs")
'Shell("explorer.exe", path + "\Resources\Logs", vbNormalFocus)
'Application.StartupPath & path + "\Resources\Logs"
'Shell(path + "\Resources\Logs", vbNormalFocus)
End Sub
Any help is greatly appreciated.
Dim MyProcess As New Process()
MyProcess.StartInfo.FileName = "explorer.exe"
MyProcess.StartInfo.Arguments = "C:\Blah"
MyProcess.Start()
MyProcess.WaitForExit()
MyProcess.Close()
MyProcess.Dispose()
Or just...
Process.Start("explorer.exe", "C:\FTP\")
Application.StartupPath is going to get you to your bin\Debug or bin\Release folder by the way, whatever folder the *.exe is in.
I'm guessing this is what you're looking for:
Process.Start("explorer.exe", Application.StartupPath & "\Resources\Logs")
Also, don't use + for joining strings. Use &
I assume you are trying to invoke Windows Explorer.
Add a trailing \ in the call to .Start
IO.Directory.CreateDirectory("C:\temp\temp")
Process.Start("c:\temp\temp\")
In the OP first example you were trying to open a file 'Logs'

Save file in a new folder?

I'm looking to make a program that will open a file and upon saving it, the program will save it into a new folder, leaving the original file unchanged.
However, none of the codes I've tried using have worked.
How do I make a new folder that will go into the FilePath of the loaded file?
How do I then save into that folder?
I tried this and got the error.. "False was not found or could not be accessed"
Private Sub SaveChangesToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveChangesToolStripMenuItem1.Click
newFilePath = FilePath + "\" + newFolderName + "Folder"
Try
Dim Writer As New PackageIO.Writer(newFilePath = orgFilePath + "\" + newFolderName, "Folder 1", PackageIO.Endian.Big)
System.IO.Directory.CreateDirectory(newFilePath)
I tried this code here and it seemed to be the closest to working, but said the file path wasn't valid; I'm assuming because it's including the file they selected, not just the folders involved.
Private Sub SaveChangesToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveChangesToolStripMenuItem1.Click
newFilePath = FilePath + "\" + newFolderName + "Folder"
Try
Dim Writer As New PackageIO.Writer(newFilePath, PackageIO.Endian.Big)
System.IO.Directory.CreateDirectory(newFilePath)
Try something along these lines:
Dim orgFilePath as String
Dim newFolderName as String
Dim newFilePath as String
'you will need to set the path of the original file and give a name for the new folder
newFilePath = orgFilePath + "\" + newFolderName
'creates new directory (folder)
System.IO.Directory.CreateDirectory(newFilePath)
'then put the code to save your file to the newFilePath variable
Hope that helps

import image to picture box from desktop user

I want to import a picture from folder which created by project when installed on user desktop but each user have different user name , how can i import from picture from dsektop user
Here is My code
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles Button2.Click
PictureBox1.Image = Image.FromFile("(My.Computer.FileSystem.SpecialDirectories.Desktop, "New folder") \" + ID.Text + ".png")
end sub
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
this will resolve to the desktop folder for the current user. Are you really creating folders on the desktop? Usually data and subfolders are stored in AppData.
EDIT
I SUSPECT you might have need of this folder in other places and even if not it can be saved and 'fixed' before hand. Elsewhere, like when the app starts:
Friend mUserFolder As String
mUserFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
' your code was not adding the required backslash
mUserFolder &= "\Data\" ' append the sub folder name
Now to load the file in button click the code is simpler to read and debug:
PictureBox1.Image = Image.FromFile(muserFolder & ID.Text & ".png")
Also use & for concatenating strings instead of +