A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Create shortcuts with a .NET application
This tutorial will show you the code you need to write to have your application create shortcuts to any path (the desktop, startup folder, etc.).
On Friday, June 10th 2005 at 11:57 AM
By Andrew Pociu (View Profile)
(Rated 4.8 with 50 votes)
CreatingShortcuts.zip (56.8 KB)
Creating a shortcut from within a C# Windows application is not as easy as using a method in a namespace of the .NET framework. However, after you'll be reading this tutorial, you'll find that it's not rocket science either. For testing purposes, you can create a Windows Forms applications, and add a button on it: btnShortcut. Double-clicking the button will bring you to the btnShortcut_Click event, where we will write some lines of code that will actually create the shortcut.
But before that, we need to add a reference to Windows Script Host Object Model. To do that, right-click the "References" folder in Solution Explorer and choose "Add Reference". From the COM tab, choose Windows Script Host Object Model. Double click it, and it will be added to the "Selected Components" list:
Now click OK and let's get to coding. You can see in the Solution Explorer that we know have IWshRuntimeLibrary added. So we don't have to write long lines of code, let's add a "using" directive in the Form1.cs file:
Next we shall create WshShell, an object of type WshShellClass:
Now inside the "click" event of the button, we do the coding:
Notice that we choosed the path to the current application, as the TargetPath, but you can set the shortcut to point to any file you want:
The description of the shortcut is also shown when in the tooltip, when the cursor is over the icon.
Currently, we set the location of the icon for the shortcut to app.ico, located inside the project's Debug folder (Application.StartupPath). app.ico is included in the project.
However, you can always change the path for the icon to something like:
If you download and run the project, it will create a shortcut to itself (the executable inside bin\Debug directory) in C:\, as can be seen here:
|Digg It! Del.icio.us Reddit StumbleIt Newsvine Furl BlinkList|
Rate this tutorial
There are no related tutorials.
Related Source Code
There is no related source code.
C# Job Search
From the creators of Geekpedia, a revolutionary new coupon website!
BargainEZ has coupons codes, printable coupons, bargains and it is the leading source of Passbook coupons for iPhone and iPod touch devices.