Trying to saving URLs, big problems! :-(
-
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" ;-) -
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" ;-)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
-
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
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?
-
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?
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 IfRageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
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 IfRageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Hi Dave, When I put the code in there it tells me that "WriteLine" is not part of System.IO.Stream???
: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 IfRageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
: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 IfRageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
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
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
-
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
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