Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Trying to saving URLs, big problems! :-(

Trying to saving URLs, big problems! :-(

Scheduled Pinned Locked Moved Visual Basic
windows-adminlinuxhelpquestion
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Darshon
    wrote on last edited by
    #1

    Hi All, Ok I've been at this for a week now and obviously I don't get it. I've got some of the code right cause it does work but as soon as I try to save a url it tells me that URI's cannot be put into a richtext box. ?? I have a button that opens a SaveFileDialog box and the way it is now works just fine but when I try to save the url that's in my AxWebBrowser it doesn't work. What I am doing wrong here? What am I just not getting? (Yes Newbbie ;-)) This is my code for the button so far: Private Sub Faves_b_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Faves_b.Click ' Find the directory of the user's Favorites. Dim objRegKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser Dim objFav As Microsoft.Win32.RegistryKey = objRegKey.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders") Dim strFavoritesPath As String = objFav.GetValue("Favorites") ' Set properties of Dialog-box. Dim myStream As Stream Dim SaveFileDialog As New SaveFileDialog Dim URLName = AxWebBrowser.LocationName Dim URLAddress = AxWebBrowser.LocationURL SaveFileDialog.Title = "Add To Your Favorites" SaveFileDialog.InitialDirectory = strFavoritesPath SaveFileDialog.FileName = URLName SaveFileDialog.Filter = "URL Files (*.url)|*.url" SaveFileDialog.FilterIndex = 1 SaveFileDialog.DefaultExt = "*.url" SaveFileDialog.RestoreDirectory = True ' Now display the SaveFileDialog so the user can save the url. SaveFileDialog.ShowDialog() ' If the file name is not an empty string save it . If SaveFileDialog.FileName <> "" Then Dim RichTextBox As New RichTextBox RichTextBox1.LoadFile(URLAddress) RichTextBox.SaveFile(URLAddress, RichTextBoxStreamType.RichText) End If End Sub Thanx to anyone that can contribute to the "Help the Newbbie Program" ;-)

    D 1 Reply Last reply
    0
    • D Darshon

      Hi All, Ok I've been at this for a week now and obviously I don't get it. I've got some of the code right cause it does work but as soon as I try to save a url it tells me that URI's cannot be put into a richtext box. ?? I have a button that opens a SaveFileDialog box and the way it is now works just fine but when I try to save the url that's in my AxWebBrowser it doesn't work. What I am doing wrong here? What am I just not getting? (Yes Newbbie ;-)) This is my code for the button so far: Private Sub Faves_b_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Faves_b.Click ' Find the directory of the user's Favorites. Dim objRegKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser Dim objFav As Microsoft.Win32.RegistryKey = objRegKey.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders") Dim strFavoritesPath As String = objFav.GetValue("Favorites") ' Set properties of Dialog-box. Dim myStream As Stream Dim SaveFileDialog As New SaveFileDialog Dim URLName = AxWebBrowser.LocationName Dim URLAddress = AxWebBrowser.LocationURL SaveFileDialog.Title = "Add To Your Favorites" SaveFileDialog.InitialDirectory = strFavoritesPath SaveFileDialog.FileName = URLName SaveFileDialog.Filter = "URL Files (*.url)|*.url" SaveFileDialog.FilterIndex = 1 SaveFileDialog.DefaultExt = "*.url" SaveFileDialog.RestoreDirectory = True ' Now display the SaveFileDialog so the user can save the url. SaveFileDialog.ShowDialog() ' If the file name is not an empty string save it . If SaveFileDialog.FileName <> "" Then Dim RichTextBox As New RichTextBox RichTextBox1.LoadFile(URLAddress) RichTextBox.SaveFile(URLAddress, RichTextBoxStreamType.RichText) End If End Sub Thanx to anyone that can contribute to the "Help the Newbbie Program" ;-)

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      All youre'trying to do is save a URL as a shortcut somewhere, right? Deceptively easy! Have you ever just opened one in Notepad? All you have to do is create a normal text file, with the filename ending in .URL and write this to it:

      [InternetShortcut]
      URL=urlPath
       
       
      For example, Yahoo.URL:
      [InternetShortcut]
      URL=http://www.yahoo.com/

      I have no idea what you're trying to do with a RichTextBox. It doesn't support loading HTML files... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome -- modified at 10:19 Thursday 9th February, 2006

      D 1 Reply Last reply
      0
      • D Dave Kreskowiak

        All youre'trying to do is save a URL as a shortcut somewhere, right? Deceptively easy! Have you ever just opened one in Notepad? All you have to do is create a normal text file, with the filename ending in .URL and write this to it:

        [InternetShortcut]
        URL=urlPath
         
         
        For example, Yahoo.URL:
        [InternetShortcut]
        URL=http://www.yahoo.com/

        I have no idea what you're trying to do with a RichTextBox. It doesn't support loading HTML files... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome -- modified at 10:19 Thursday 9th February, 2006

        D Offline
        D Offline
        Darshon
        wrote on last edited by
        #3

        Hey someone answered. lol I posted this in a couple of different forums and this is the only one that's answered me. Yes all I'm trying to do is save a url link from my browser. That's it! I've tried just saving a text file with the url extension but again I must be doing something wrong cause I can't seem to get it to write on the file. Can you help me out with this too?

        D 1 Reply Last reply
        0
        • D Darshon

          Hey someone answered. lol I posted this in a couple of different forums and this is the only one that's answered me. Yes all I'm trying to do is save a url link from my browser. That's it! I've tried just saving a text file with the url extension but again I must be doing something wrong cause I can't seem to get it to write on the file. Can you help me out with this too?

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Well, in the code that you posted, you didn't open any file and write anything to it. The RichTextBox won't do anything for you and you're using it's methods incorrectly. You're looking for something most like this:

          If SaveFileDialog.ShowDialog = DialogResult.OK Then
          Dim fs As Stream = SaveFileDialog.OpenFile()
          If Not (fs Is Nothing) Then
          fs.WriteLine("[InternetShortcut]")
          fs.WriteLine(String.Format("URL={0}", URLAddress))
          fs.Close()
          End If
          End If

          RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          D 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Well, in the code that you posted, you didn't open any file and write anything to it. The RichTextBox won't do anything for you and you're using it's methods incorrectly. You're looking for something most like this:

            If SaveFileDialog.ShowDialog = DialogResult.OK Then
            Dim fs As Stream = SaveFileDialog.OpenFile()
            If Not (fs Is Nothing) Then
            fs.WriteLine("[InternetShortcut]")
            fs.WriteLine(String.Format("URL={0}", URLAddress))
            fs.Close()
            End If
            End If

            RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            D Offline
            D Offline
            Darshon
            wrote on last edited by
            #5

            Hi Dave, When I put the code in there it tells me that "WriteLine" is not part of System.IO.Stream???

            D 1 Reply Last reply
            0
            • D Darshon

              Hi Dave, When I put the code in there it tells me that "WriteLine" is not part of System.IO.Stream???

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              :doh: Too damn sleepy last night. A little simpler:

              If SaveFileDialog.ShowDialog = DialogResult.OK Then
              Dim sw As New StreamWriter(SaveFileDialog.FileName)
              sw.WriteLine("[InternetShortcut]")
              sw.WriteLine(String.Format("URL={0}", URLAddress))
              sw.Close()
              End If

              RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              D 1 Reply Last reply
              0
              • D Dave Kreskowiak

                :doh: Too damn sleepy last night. A little simpler:

                If SaveFileDialog.ShowDialog = DialogResult.OK Then
                Dim sw As New StreamWriter(SaveFileDialog.FileName)
                sw.WriteLine("[InternetShortcut]")
                sw.WriteLine(String.Format("URL={0}", URLAddress))
                sw.Close()
                End If

                RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                D Offline
                D Offline
                Darshon
                wrote on last edited by
                #7

                Hi Dave, Thank you very much, it works just fine now. :) Now that I can add to favorites, the next step is to open them in my WebBrowser. Thanks for your help

                D 1 Reply Last reply
                0
                • D Darshon

                  Hi Dave, Thank you very much, it works just fine now. :) Now that I can add to favorites, the next step is to open them in my WebBrowser. Thanks for your help

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  Start it in a browser on your form or just launch the thing like someone double-clicked the shortcut on the desktop? If it's to launch the shortcut like double-clicking it, then all you have to use is use the Process class.

                  Dim newProcess As New Process("filename.url")
                  newProcess.Start()

                  If it's a browser on your form, then all you have to do is call the browser's .Navigate() method, passing in the full path to the *.URL file.

                  WebBrowser1.Navigate("filename.url")

                  RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                  D 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    Start it in a browser on your form or just launch the thing like someone double-clicked the shortcut on the desktop? If it's to launch the shortcut like double-clicking it, then all you have to use is use the Process class.

                    Dim newProcess As New Process("filename.url")
                    newProcess.Start()

                    If it's a browser on your form, then all you have to do is call the browser's .Navigate() method, passing in the full path to the *.URL file.

                    WebBrowser1.Navigate("filename.url")

                    RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                    D Offline
                    D Offline
                    Darshon
                    wrote on last edited by
                    #9

                    HI Dave, Yeah I want to open the url link in my browser on my form. The Code you wrote is what I was thinking of putting. Glad to see I'm thinking in the right direction. :-) One thing though that I noticed as I was testing the first code you helped me on was that the names of some pages have these "<, >, *, |, :, \, /, &, %, ", ., #, ?" type characters and therefore the expected error comes up that the page name is not valid for saving. Now if you remember I'm taking the Variable URLName = WebBrowser.LocationURL string and using that as the SaveFileDialog.FileName. Could you dirrect me in the right track in order to check if the URLName variable has any of those characters and change them to a usable character like maybe the "-" or "_" characters before it is used in the SAveFileDialog box as the FileName? -- modified at 23:39 Friday 10th February, 2006

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups