Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
It works Fine using VB Web Developer om my laptop but having Problems on My Web Site.

Pressing Button 1 brings up the Error ("Cannot Find The Directory DESKTOP")

VB
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    
        Try
            WriteShortcut("http://www.mylighthousecove-fl.org/", IO.Path.Combine _
		(My.Computer.FileSystem.SpecialDirectories.Desktop, "LHC Blog.url"))
        Catch

           ''''''''''''''Note '''''''''''Errors out here
         
        End Try

    End Sub

 Sub WriteShortcut(ByVal url As String, ByVal filename As String)
        Try
            My.Computer.FileSystem.WriteAllText(filename,String.Format _
                ("InternetShortcut]{0}URL={1}{0}",vbCrLf, url), False)
        Catch

        End Try

    End Sub
Posted
Updated 2-Jan-12 9:37am
v4
Comments
Dinesh Mani 2-Jan-12 23:34pm    
Why do you want to write something onto your server file system from a web application?? This is very dangerous and can lead to breakins on your server...

BTW, you do know that this piece of code would write to the server, right???
Tom Moody 3-Jan-12 6:52am    
Just trying to put a url Shortcut on the users desktop if they want it. I'm not trying to write to the server file system but to the users file system. If you have a better solution i sure could use it.
Thanks.. tom
Dave Kreskowiak 11-Feb-12 19:17pm    
Yeah, that's not going to happen from your VB.NET code. All ASP.NET code runs server-side and has no access to the client machines at all.

The code you use would have to be done in script in the page you send to the brwoser. Oh, BTW, the clients filesystem is off-limits to any code running in the browser.

Gave up on Downloading a url Icon and Posted a method users can do themselves.

How To Create a Shortcut To This Site

[On Your Computer]

1. Right Click on the {START} Button
2. Click on {Explore} to open the Windows Explorer
3. Scroll up and select the folder{Desktop}
4. Click on [File} and select {New}
5. Select {Shortcut]
6. Copy The following and paste it into the TextBox "http://www.xxxxx.org"
7. Click {Next} and in the Name TextBox type The Following "NAME"
 
Share this answer
 
Comments
RaviRanjanKr 6-Jan-12 16:19pm    
A suggestion :- you can use Have a question or Comment button to drop your message and to get Immediate response instead of posting as answer.
This worked for me, perhaps it will work for you:


Private Sub CreateShortCut(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim Shell As New WshShell
Dim ShortcutName As String = "Name of shortcurt"
Dim DesktopDir As String = _
CType(Shell.SpecialFolders.Item("AllUsersDesktop"), String)
Dim shortCut As IWshRuntimeLibrary.IWshShortcut

' short cut files have a .lnk extension
shortCut = CType(Shell.CreateShortcut(DesktopDir & "\" & _
ShortcutName & ".lnk"), _
IWshRuntimeLibrary.IWshShortcut)
With shortCut ' set the shortcut properties
.TargetPath = "http://" & ServerString & ":8080/more/main.do"
.WindowStyle = 1
.Description = "Description of Shortcut"
.WorkingDirectory = DesktopDir
'use reflection to get the first Icon from the app
.IconLocation = "Path of special icon I wanted to use for shortcut" & ", 0"
.Save() ' save the shortcut file
End With

Me.Close()

End Sub
 
Share this answer
 
v3

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