הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Sunday, May 8, 2016 12:25 PM
Hi
In my app I need to store the URL without the http:// or https://
So if given say http://www.google.co.uk or https://social.msdn.microsoft.com then I just want www.google.co.uk or social.msdn.microsoft.com returned
@ Frank - if you are reading as you may have come across this issue with DevExpress controls:-
My reasoning for doing this is that the DevExpress ComboBoxEdit control doesn't have such good autocomplete as the standard Windows control
For example in DevExpress control if I start typing www in the box it only shows entries starting with that, but most entries start with http:
But with the standard windows control I could set AutoCompleteSource.AllUrl and then it would do autocomplete for any entries which contained the text I typed anywhere in the string
Hence wanting to store the url minus the http:// or https://
Darren Rose
All replies (42)
Sunday, May 8, 2016 12:32 PM ✅Answered
You can use the String.Replace method or even the String.SubString method along with the String.IndexOf method.
Example of using the Replace method:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim s As String = "http://www.google.co.uk"
s = s.Replace("http://", "").Replace("https://", "")
MessageBox.Show(s)
End Sub
If you say it can`t be done then i`ll try it
Monday, May 9, 2016 4:26 PM ✅Answered
Okay I will try and follow - as long as finished idea can still be used with listview - as I say my basic app cannot use DevExpress controls at all
Darren Rose
Darren,
Well in worst case just don't use it, but this could be shown in a DataGridView or ListView, it just doesn't have the great functionality that it could have using Dev's GridControl.
I'll show you what I mean by the end of this post.
*****
I'm sure that it comes as no surprise that I built a class library from this stuff. There are two collection classes in that library: "Links" and "History", along with methods that work with that data (including writing and reading XML files).
The default is to use the "Save" and "Load" methods to read and write binary files, but it's up to you whether you ever call it or not.
The two binary files (if you view them using Notepad) look like this:
As you can see, there's no size savings to be had for string data, at least not using the out-of-the-box serialization built into dotNet.
Also though (not a concern here but keep it in mind) - what if that were sensitive information? You can't avoid it being "readable", so if that comes up in the future, consider doing this:
Create the binary file in a temporary directory (that you control), then using something like what we did a few months ago, create an encrypted zip file. That zip file is then saved and the temporary binary file is deleted. On the way back in, just reverse the process.
Addressing the XML files though, I’ve set it up to use attributes rather than elements (to save size) and they look like the following:
You can see that they’re fairly concise files so they should load pretty quickly relative to the amount of data that’s in them.
For your program though, use the classes (once the data has been retrieved from either the binary file or the XML file). That’s what it’s set up to do.
In my mind, the binary file is the local version and it’s written to the user’s ApplicationData folder which is created by the class library if it doesn’t exist.
But that doesn’t mean that the XML is therefore useless at all. In fact with the “Links” XML file, I have it set up so that your users could share links. If you use the optional Boolean parameter and tell it NOT to clear the internal list, then it will look through the XML file and look for any entries which aren’t already in their own collection.
There are two caveats to be aware of: The URL has to be unique so using the method that I just described, if the URL is already in the internal collection, it’s not added. Also though, the DisplayName has to be unique (for obvious reasons). That’s also then verified that they don’t already have a link (to any URL) using that display name and, if found, it’s not added.
Did you notice, in the XML above for the links, a new field there that’s not in yours? The host of the URL is pulled out by creating a new URI and getting it from there. This is the part that I have added, both because it’s potentially useful, and so that I could demonstrate something with the Dev GridView control. I’ll explain by example, but first I have to explain what I’m about to show you:
*****
My daughter is now grown, graduated from college (twice – two different colleges; to different degrees), married and off living happily ever after and all that.
Well when she was living here, throughout the week I’d read a news article or human interest article or see a video that I’d then create a link to and I put those links on my desktop. That following weekend, I’d get her to watch them – and we both enjoyed the time together, talking about whatever she just read, etc..
Alas, those days are in the past so about a year ago (maybe longer) I set up a program that uses XML data that’s on my website. I update it at least once a week. The purpose is to have a display of links along with the title and allow the user to open that link in their default browser.
In that program I also set it up to get the Host and I did that for one main purpose as demonstrated below:
No surprises there, but the “Host” column is set up to be “groupable” (if that’s a word). The user can click and hold the column header and s-l-i-d-e it into the group area just above the grid:
If I now expand one of those groups:
Unrelated, but I have it set up so that double-clicking a row will open the URL in their default browser and they also have a context menu available to them:
*****
The project directory is zipped up and uploaded at the URL below, and the program’s code can be seen on a page of my website here. I’m doing something a little special with the date (in “History”) and I’ll explain that once you get caught up.
http://www.fls-online.com/VBNet_Forum/05-09-16/Test_LinksAndHistory.zip
I hope this might give you food for thought. :)
In the middle of difficulty ... lies opportunity. -- Albert Einstein
Sunday, May 8, 2016 12:38 PM
Thanks IronRazerz - that works well
Taking this one step further - any way to "validate" and URL is correct before trying to use it in an app - i.e. perhaps checking valid format and even whether it exists?
Darren Rose
Sunday, May 8, 2016 12:58 PM | 1 vote
Thanks IronRazerz - that works well
Taking this one step further - any way to "validate" and URL is correct before trying to use it in an app - i.e. perhaps checking valid format and even whether it exists?
Darren Rose
I never noticed it, honestly.
You might try this for the last part (and actually do try it, so you'll understand what's going on and why the first one returns false):
Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim test1 As Boolean = UrlIsValid("http://www.fls-online.com")
Dim test2 As Boolean = UrlIsValid("http://www.google.com")
Stop
End Sub
Private Function UrlIsValid(ByVal url As String) As Boolean
Dim retVal As Boolean = False
Try
If Not String.IsNullOrWhiteSpace(url) Then
Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(url)
Using response As System.Net.HttpWebResponse = _
DirectCast(request.GetResponse, System.Net.HttpWebResponse)
If response IsNot Nothing Then
retVal = True
End If
End Using
End If
Catch ex As Exception
' Nothing to do ... It will return false.
End Try
Return retVal
End Function
End Class
In the middle of difficulty ... lies opportunity. -- Albert Einstein
Sunday, May 8, 2016 1:04 PM
Thanks IronRazerz - that works well
Taking this one step further - any way to "validate" and URL is correct before trying to use it in an app - i.e. perhaps checking valid format and even whether it exists?
Darren Rose
The only way you can tell if it exists is to try connecting to it. Try the suggestions in these links that use a WebReqest.
VB.NET how to check if a webpage exists
As far as checking if it is in a valid format, i guess you could use the Uri class and try creating a Uri from the Url.
Dim validUri As Uri
If Uri.TryCreate("Your Url", UriKind.RelativeOrAbsolute, validUri) Then
MessageBox.Show("Valid Format")
Else
MessageBox.Show("Not Valid Format")
End If
If you say it can`t be done then i`ll try it
Sunday, May 8, 2016 1:13 PM
@Frank
Thanks I see how it works - for first one it returns false due to access denied on website?
Trouble is it doesn't work for incorrect URL's as some sites seem to just redirect i.e.
returns true for me - when obviously a wrong URL
Darren Rose
Sunday, May 8, 2016 1:19 PM
@Frank
Thanks I see how it works - for first one it returns false due to access denied on website?
Trouble is it doesn't work for incorrect URL's as some sites seem to just redirect i.e.
returns true for me - when obviously a wrong URL
Darren Rose
Dim test3 As Boolean = UrlIsValid("http://www.gofffogle.coddfm")
That returns false.
Did I mistype it?
In the middle of difficulty ... lies opportunity. -- Albert Einstein
Sunday, May 8, 2016 1:29 PM
that is odd - returns true for me
Darren Rose
Sunday, May 8, 2016 1:32 PM
that is odd - returns true for me
Darren Rose
I don't know, but try it this modified way and let me know your results?
Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim test1 As Boolean = HttpUrlIsValid("http://www.fls-online.com")
Dim test2 As Boolean = HttpUrlIsValid("http://www.google.com")
Dim test3 As Boolean = HttpUrlIsValid("http://www.gofffogle.coddfm")
Stop
End Sub
Private Function HttpUrlIsValid(ByVal url As String) As Boolean
Dim retVal As Boolean = False
Try
If Not String.IsNullOrWhiteSpace(url) Then
Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(url)
Using response As System.Net.HttpWebResponse = _
DirectCast(request.GetResponse, System.Net.HttpWebResponse)
If response IsNot Nothing Then
If response.StatusCode = Net.HttpStatusCode.OK Then
retVal = True
End If
End If
End Using
End If
Catch ex As Exception
' Nothing to do ... It will return false.
End Try
Return retVal
End Function
End Class
In the middle of difficulty ... lies opportunity. -- Albert Einstein
Sunday, May 8, 2016 1:35 PM
@Frank
Thanks I see how it works - for first one it returns false due to access denied on website?
Trouble is it doesn't work for incorrect URL's as some sites seem to just redirect i.e.
returns true for me - when obviously a wrong URL
Darren Rose
You can use Dns.GetHostEntry Method (String) and catch the exception using a function returning a boolean. If no exception then true or if an exception return false.
This will return information, IPHostEntry, which you probably do not need however it validates whether the Domain Name Server can return anything for the URL used.
La vida loca
Sunday, May 8, 2016 1:42 PM
Darren,
I have to leave in about a half-hour and I won't be back until later this afternoon.
If it's still not working right, put a breakpoint in:
When it stops, hover your mouse over the response and see if you can garner any bit of information about what's going on.
*****
You don't need an XMLTextWriter - use LINQ-To-XML to take care of all that for you.
Different topic though. ;-)
In the middle of difficulty ... lies opportunity. -- Albert Einstein
Sunday, May 8, 2016 1:53 PM
@Frank
Can't see anything obvious - very odd as it returns Status Code OK 200
All I can think is that it is something to do with my ISP as if I open that page in browser then it takes me to a custom page not found page showing my ISP's name - so perhaps as it is redirecting to another site it then thinks it is OK - if so then probably no point me worrying, as a lot of genuine sites use redirects
****
re: XMLTextWriter - We will come back to that later perhaps - as I use it for a couple of different areas in this app
****
@ Mr MonkeyBoy - will try that
Darren Rose
Sunday, May 8, 2016 1:57 PM
Darren,
Sorry it doesn't work on your end. I don't know - it returns false here.
In the middle of difficulty ... lies opportunity. -- Albert Einstein
Sunday, May 8, 2016 1:57 PM
Just to butt in one more time, with a quick test on just the url you where trying, this seems to work.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim StrUrl As String = "http://www.gofffogle.coddfm"
If IsUrlValidFormat(StrUrl) Then
MessageBox.Show("Valid Format")
Else
MessageBox.Show("Not Valid Format")
End If
If DoesUrlExist(StrUrl) Then
MessageBox.Show("Exists")
Else
MessageBox.Show("Does not exist")
End If
End Sub
Private Function IsUrlValidFormat(ByVal url As String) As Boolean
Dim validUri As Uri = Nothing
If Uri.TryCreate(url, UriKind.RelativeOrAbsolute, validUri) Then
Return True
Else
Return False
End If
End Function
Private Function DoesUrlExist(ByVal url As String) As Boolean
Dim req As Net.WebRequest = Net.WebRequest.Create(url)
Try
Dim res As Net.WebResponse = req.GetResponse()
res.Dispose()
Return True
Catch ex As Net.WebException
Return False
End Try
End Function
End Class
If you say it can`t be done then i`ll try it
Sunday, May 8, 2016 2:01 PM
Darren,
Sorry it doesn't work on your end. I don't know - it returns false here.
In the middle of difficulty ... lies opportunity. -- Albert Einstein
That's okay - thanks for trying
I assume if you try to open that URL in Internet Explorer you get a page cannot be displayed or similar message?
Darren Rose
Sunday, May 8, 2016 2:03 PM
@IronRazerz
I assume for you it comes back and says "Does not exist"?
For me it comes back as "Exists" .......
Must be something to do with my ISP redirecting errors or similar then
Darren Rose
Sunday, May 8, 2016 2:07 PM
You can use Dns.GetHostEntry Method (String) and catch the exception using a function returning a boolean. If no exception then true or if an exception return false.
This will return information, IPHostEntry, which you probably do not need however it validates whether the Domain Name Server can return anything for the URL used.
La vida loca
This method also doesn't seem to work for me - again think it must be as my ISP is redirecting error pages or something - as any wrong url redirects to a custom page telling me page can't be found - rather than just the standard IE page cannot be found message - this must be confusing the code due to the redirects perhaps
Darren Rose
Sunday, May 8, 2016 2:30 PM
@Frank - different subject I know so perhaps should create separate thread - but interested in your comment about XML and perhaps better way to do below if I am doing it wrong
Private Sub SaveLinksXML()
Dim tw As XmlTextWriter = New XmlTextWriter(linksName, System.Text.Encoding.UTF8)
tw.Formatting = Formatting.Indented
tw.WriteStartElement("Items")
tw.WriteAttributeString("version", "1.0")
tw.WriteAttributeString("application", Application.ProductName)
tw.WriteStartElement("Homepage")
tw.WriteElementString("Home", HomePage)
tw.WriteEndElement()
tw.WriteStartElement("Favorites")
For i = 0 To lvwLinks.Items.Count - 1
tw.WriteElementString("Favorite", lvwLinks.Items(i).Tag.ToString(), lvwLinks.Items(i).Text.ToString)
Next i
tw.WriteEndElement()
tw.WriteEndElement()
tw.Close()
End Sub
and
Private Sub SaveHistoryXML()
Dim tw As XmlTextWriter = New XmlTextWriter(historyName, System.Text.Encoding.UTF8)
tw.Formatting = Formatting.Indented
tw.WriteStartElement("Items")
tw.WriteAttributeString("version", "1.0")
tw.WriteAttributeString("application", Application.ProductName)
tw.WriteStartElement("History")
For i = 0 To cbAddress.Items.Count - 1
' only saves history items if less than x days old (stored in My.Settings.HistoryDaysToSave to keep file clean
Dim historyitemdate As DateTime = ComboBoxDate.Item(i)
If DateTime.Compare(historyitemdate, DateTime.Now.AddDays(-My.Settings.HistoryDaysToSave)) = 1 Then
tw.WriteElementString("History", ComboBoxDate.Item(i).ToString, cbAddress.Items(i).ToString)
End If
Next
tw.WriteEndElement()
tw.WriteEndElement()
tw.Close()
End Sub
Darren Rose
Sunday, May 8, 2016 2:55 PM
You can use Dns.GetHostEntry Method (String) and catch the exception using a function returning a boolean. If no exception then true or if an exception return false.
This will return information, IPHostEntry, which you probably do not need however it validates whether the Domain Name Server can return anything for the URL used.
La vida loca
This method also doesn't seem to work for me - again think it must be as my ISP is redirecting error pages or something - as any wrong url redirects to a custom page telling me page can't be found - rather than just the standard IE page cannot be found message - this must be confusing the code due to the redirects perhaps
Darren Rose
I'm not certain what you mean. That code gets a response from a Domain Name Server. If the URL in question does not exist then the Doman Name Server can not return anything for it therefore an exception occurs.
How you are using the method may be the issue. It works fine if the PC is online. If the actual WebSite the URL pertains to is down for whatever reason temporarily this will not know that.
Option Strict On
Imports System.Net
Public Class Form1
Dim Addresses As New List(Of String)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Addresses.Add("www.gofffogle.coddfm")
Addresses.Add("www.google.com")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
RichTextBox1.Clear()
For Each Item In Addresses
RichTextBox1.AppendText(Item & " is valid = " & ValidateURL(Item).ToString & "." & vbCrLf)
Next
End Sub
Public Function ValidateURL(ByRef hostName As String) As Boolean
Try
Dim host As IPHostEntry = Dns.GetHostEntry(hostName)
Return True
Catch ex As Exception
Return False
End Try
End Function
End Class
La vida loca
Sunday, May 8, 2016 3:05 PM
I'm not certain what you mean. That code gets a response from a Domain Name Server. If the URL in question does not exist then the Doman Name Server can not return anything for it therefore an exception occurs.
How you are using the method may be the issue.
La vida loca
The point is - even if the URL doesn't exist it is still returning a value - because it is returning the value of the site it redirected too when telling me domain doesn't exist
I used code and then looked at values it held for both correct site and wrong site - for correct site (www.google.co.uk) it had IP of 172.217.20.131 which is a Google IP - for a wrong address (www.gofgffgfogle.co.ukfgf) it has IP of 92.242.132.15 which is my ISP
Doing same site in a browser shows me a custom page from my ISP saying no such page, so must be redirecting
Code I used was similar to below - and I was just looking a values held in r when it ran
Dim r As Net.IPHostEntry = Net.Dns.GetHostEntry("www.gofgffgfogle.co.ukfgf")
Darren Rose
Sunday, May 8, 2016 3:34 PM
I'm not certain what you mean. That code gets a response from a Domain Name Server. If the URL in question does not exist then the Doman Name Server can not return anything for it therefore an exception occurs.
How you are using the method may be the issue.
La vida loca
The point is - even if the URL doesn't exist it is still returning a value - because it is returning the value of the site it redirected too when telling me domain doesn't exist
I used code and then looked at values it held for both correct site and wrong site - for correct site (www.google.co.uk) it had IP of 172.217.20.131 which is a Google IP - for a wrong address (www.gofgffgfogle.co.ukfgf) it has IP of 92.242.132.15 which is my ISP
Doing same site in a browser shows me a custom page from my ISP saying no such page, so must be redirecting
Code I used was similar to below - and I was just looking a values held in r when it ran
Dim r As Net.IPHostEntry = Net.Dns.GetHostEntry("www.gofgffgfogle.co.ukfgf")
Darren Rose
My ISP doesn't do that so the code works fine for me.
I suppose programmers using your ISPs DNS to validate urls using this method have to provide appropriate methods to determine if your ISP's address is being returned rather than no address (exception) for the url in question. Either that or alter something in the router or somewhere to disable this capability. My webbrowser simply displays the below as it always has for every ISP I've ever used.
It's nice to know that if a program is written to use this method to validate URLs that there are ISPs out there which have to be accounted for returning values for something that does not exist though.
La vida loca
Sunday, May 8, 2016 3:44 PM | 1 vote
Yes indeed - mine shows this page instead - so must be something on router on in the ISP DNS configuration
Darren Rose
Sunday, May 8, 2016 5:06 PM
Yes indeed - mine shows this page instead - so must be something on router on in the ISP DNS configuration
Darren Rose
Yes I suppose.
I worked at BT in Ipswich for two weeks once so they could test telephone via satellite for various telephone interface types via the satellite system (specialized routers/satellite transmitters and receivers in separate cabinets and satellite dishes) I and a friend installed.
Went to Felixstowe for Fish -n- Chips one weekend driving a rented Vauxhall on the wrong side of the road. :/
Oh yeah, the Fish -n- Chips were awesome with the vinegar to use for eating them which I'd never tried Fish with vinegar before. Along with a pint of something or another. I also brought a duffel bag full of different types of British beers back and gave them out to people at the company so they could try them. I think they're alot stronger by % alcohol by vol than beers made in non-micro breweries in the U.S. or imported to the U.S. for some reason.
La vida loca
Sunday, May 8, 2016 5:08 PM | 1 vote
Yes I suppose.
I worked at BT in Ipswich for two weeks once so they could test telephone via satellite for various telephone interface types via the satellite system I and a friend installed.
Went to Felixstowe for Fish -n- chips one weekend driving a rented Vauxhall on the wrong side of the road. :/
La vida loca
:)
Not that many miles from me then in Norfolk
Darren Rose
Sunday, May 8, 2016 8:14 PM
@Frank - different subject I know so perhaps should create separate thread - but interested in your comment about XML and perhaps better way to do below if I am doing it wrong
Private Sub SaveLinksXML() Dim tw As XmlTextWriter = New XmlTextWriter(linksName, System.Text.Encoding.UTF8) tw.Formatting = Formatting.Indented tw.WriteStartElement("Items") tw.WriteAttributeString("version", "1.0") tw.WriteAttributeString("application", Application.ProductName) tw.WriteStartElement("Homepage") tw.WriteElementString("Home", HomePage) tw.WriteEndElement() tw.WriteStartElement("Favorites") For i = 0 To lvwLinks.Items.Count - 1 tw.WriteElementString("Favorite", lvwLinks.Items(i).Tag.ToString(), lvwLinks.Items(i).Text.ToString) Next i tw.WriteEndElement() tw.WriteEndElement() tw.Close() End Sub
and
Private Sub SaveHistoryXML() Dim tw As XmlTextWriter = New XmlTextWriter(historyName, System.Text.Encoding.UTF8) tw.Formatting = Formatting.Indented tw.WriteStartElement("Items") tw.WriteAttributeString("version", "1.0") tw.WriteAttributeString("application", Application.ProductName) tw.WriteStartElement("History") For i = 0 To cbAddress.Items.Count - 1 ' only saves history items if less than x days old (stored in My.Settings.HistoryDaysToSave to keep file clean Dim historyitemdate As DateTime = ComboBoxDate.Item(i) If DateTime.Compare(historyitemdate, DateTime.Now.AddDays(-My.Settings.HistoryDaysToSave)) = 1 Then tw.WriteElementString("History", ComboBoxDate.Item(i).ToString, cbAddress.Items(i).ToString) End If Next tw.WriteEndElement() tw.WriteEndElement() tw.Close() End Sub
Darren Rose
Darren,
Let's stay in this thread to at least get started.
Will you give me an overview of what you're saving? Is XML the only way or are you open to maybe using binary serialization?
Instead of code, for now, explain the purpose and what data you're the XML contains, then we can go from there.
In the middle of difficulty ... lies opportunity. -- Albert Einstein
Sunday, May 8, 2016 8:24 PM
Two files - one called links.xml and the other history.xml
One contains the list of websites visited - the other contains my version of favorites in one node? and the homepage in the other
Samples of files below which show what they currently look like
Please explain binary serialization? as not sure what it is
I quite like XML as use it for other bits and it seems the "in" way to do things nowadays
<Items version="1.0" application="Browser_PE">
<Homepage>
<Home>http://www.google.co.uk</Home>
</Homepage>
<Favorites>
<Favorite xmlns="https://portal.microsoftonline.com/">Microsoft Office 365 Portal</Favorite>
<Favorite xmlns="http://btbusiness.custhelp.com/app/service_status/">BT Service Status</Favorite>
<Favorite xmlns="http://www.senderbase.org/lookup/">Look Up - SenderBase - email and web reputation</Favorite>
<Favorite xmlns="http://mxtoolbox.com/SuperTool.aspx">Network Tools DNS,IP,Email,Analyze Headers, Blacklists etc</Favorite>
<Favorite xmlns="http://www.bleepingcomputer.com/">Bleeping Computer</Favorite>
<Favorite xmlns="http://theoven.org/index.php">The Oven</Favorite>
</Favorites>
</Items>
<Items version="1.0" application="Browser_PE">
<History>
<History xmlns="03/05/2016 20:25:57">http://www.bbc.co.uk/</History>
<History xmlns="03/05/2016 20:26:02">http://www.bbc.co.uk/sport/live/football/35947310</History>
<History xmlns="04/05/2016 17:26:56">https://whatbrowser.org/</History>
<History xmlns="04/05/2016 17:28:37">https://www.google.co.uk/?gws_rd=ssl#q=what+brwser</History>
<History xmlns="04/05/2016 17:28:48">http://www.whatsmybrowser.org/</History>
</History>
</Items>
Darren Rose
Sunday, May 8, 2016 8:37 PM
Darren,
The result looks pretty good. I don't see the purpose of the application tag though.
Also, is there a reason you're using a namespace in the XML files?
*****
Tomorrow - you won't have time tonight your time - have a look at a thread that I was involved in not quite a year ago:
You'll need to scroll down some, but look for one (from me to the OP - named Chris) that starts with the following:
"Chris,
Let's start with this. First, please download this zip file and the contents..."
That's a long thread - quite involved - but if you'll read it in detail I think you'll see that I'm showing a lot about using LINQ-To-XML, both reading and writing it, and both elements and attributes. I also make a comparison between XML and using a CSV file.
We'll talk about binary serialization before all of this is over with (and there's a go-between -- a special kind of XML file that has some of the benefits of binary serialization), but that's for later.
The thread is quite long and it gets involved, so do know that in advance. When you can set aside some time to study it though, I think it will make things easier here. :)
In the middle of difficulty ... lies opportunity. -- Albert Einstein
Sunday, May 8, 2016 8:51 PM
The code is based on something I found on internet which I copied and modified for my own use - so no idea why I am using application tag - but certainly not needed, and didn't realise I was using a namespace, but after looking again I assume that is what xmlns means - again probably not needed, purpose of files is very basic just to store a list of urls and a date or name depending on file
***
Okay I will give that a read tomorrow and see what I understand from it - thanks
Darren Rose
Sunday, May 8, 2016 8:58 PM
The code is based on something I found on internet which I copied and modified for my own use - so no idea why I am using application tag - but certainly not needed, and didn't realise I was using a namespace, but after looking again I assume that is what xmlns means - again probably not needed, purpose of files is very basic just to store a list of urls and a date or name depending on file
***
Okay I will give that a read tomorrow and see what I understand from it - thanks
Darren Rose
Ok, I understand (and yes, xmlns means "XML Namespace").
We'll talk more tomorrow and maybe even add to what's in the XML file.
We'll do it a few ways - using elements (XElements) and attributes (XAttributes) then later, when we talk about binary serialization I'll show you what I meant about SOAP (Simple Object Access Protocol)'s version of XML and how it does some things just like binary does.
*****
Read through that lonnnnnnng post though and as far as I know, all those links still work so feel free to try them if you want to. There's nothing like doing it to really cement the concepts.
More tomorrow then. :)
In the middle of difficulty ... lies opportunity. -- Albert Einstein
Monday, May 9, 2016 10:44 AM
Hi Frank
Okay I have given that thread an initial read - but will probably need to read it again as it was quite in depth (as expected :) ) - and possibly a lot more complex than I need to just write a few values from a listbox into an XML file and read them again perhaps? - but I think I get the basic ideas of it
***
Had another look at my code and can see easily how to get rid of the application tag
But as for the namespace (xmlns) no idea as I didn't choose to have it and can't see where I choose not too
Darren Rose
Monday, May 9, 2016 11:39 AM
Hi Frank
Okay I have given that thread an initial read - but will probably need to read it again as it was quite in depth (as expected :) ) - and possibly a lot more complex than I need to just write a few values from a listbox into an XML file and read them again perhaps? - but I think I get the basic ideas of it
***
Had another look at my code and can see easily how to get rid of the application tag
But as for the namespace (xmlns) no idea as I didn't choose to have it and can't see where I choose not too
Darren Rose
I'll show you how to write (export) and read (import) but that's for later.
What else do you want to add to it? One thought is what started this thread - what about a "display name" (no need to display the full URL, so long as it's unique it can be used).
What about giving your users the ability to add, modify, and delete their bookmarks? I think that would be a nice addition.
Give some thought to that and I'll be back in a bit.
In the middle of difficulty ... lies opportunity. -- Albert Einstein
Monday, May 9, 2016 1:02 PM
Hi Frank
The links.xml for favorites only shows a display name - it saves the URL and the title of the website
For history.xml it just saves full URL without http:// as per thread as it saves the values already edited above, and a date
They can already add and remove links/bookmarks - this is handled in the listview which shows them
The files are simply just to save the links/history on closing app - and then on reopening it imports links.xml into the listview and history.xml into the combobox dropdown
Darren Rose
Monday, May 9, 2016 1:16 PM
Hi Frank
The links.xml for favorites only shows a display name - it saves the URL and the title of the website
For history.xml it just saves full URL without http:// as per thread as it saves the values already edited above, and a date
They can already add and remove links/bookmarks - this is handled in the listview which shows them
The files are simply just to save the links/history on closing app - and then on reopening it imports links.xml into the listview and history.xml into the combobox dropdown
Darren Rose
You've got Dev's great stuff and you're using a 1980's ListView control?
Well, it's your call of course.
Anyway, bear with me a few hours and I'll get back to this.
In the middle of difficulty ... lies opportunity. -- Albert Einstein
Monday, May 9, 2016 1:20 PM
Fair point! I am only now finishing this app and moving over existing code and converting it to DevExpress controls - I have a list in front of me of bits still to do and listview and treeview are the only items left - so I will get it done, just found standard controls for those two items a lot easier to use
My original app unfortunately couldn't use DevExpress controls as they don't work in the environment I had made the basic browser for (Windows PE)
This new tabbed version is making full use of DevExpress DocumentManager TabbedView and Bar Manager and all other bits...
Darren Rose
Monday, May 9, 2016 1:23 PM
Fair point! I am only now finishing this app and moving over existing code and converting it to DevExpress controls - I have a list in front of me of bits still to do and listview and treeview are the only items left - so I will get it done, just found standard controls for those two items a lot easier to use
My original app unfortunately couldn't use DevExpress controls as they don't work in the environment I had made the basic browser for (Windows PE)
This new tabbed version is making full use of DevExpress DocumentManager TabbedView and Bar Manager and all other bits...
Darren Rose
When I get back to this, I'll add something in that will only really make sense if you use Dev's DataGrid. I'll explain that when I get to it though.
In the middle of difficulty ... lies opportunity. -- Albert Einstein
Monday, May 9, 2016 1:48 PM
When I get back to this, I'll add something in that will only really make sense if you use Dev's DataGrid. I'll explain that when I get to it though.
In the middle of difficulty ... lies opportunity. -- Albert Einstein
Okay I will try and follow - as long as finished idea can still be used with listview - as I say my basic app cannot use DevExpress controls at all
Darren Rose
Monday, May 9, 2016 4:56 PM
Okay that all make sense
I can confirm the files won't contain anything confidential so I don't need to go that far with it - and I prefer XML rather than binary for my use - as I sometimes manually edit the links in the file and with XML that I can do quickly and easily in Notepad++
***
Cool idea - isn't it scary how quick the years go
Darren Rose
Monday, May 9, 2016 5:02 PM
Okay that all make sense
I can confirm the files won't contain anything confidential so I don't need to go that far with it - and I prefer XML rather than binary for my use - as I sometimes manually edit the links in the file and with XML that I can do quickly and easily in Notepad++
***
Cool idea - isn't it scary how quick the years go
Darren Rose
Turn around twice and you're ten years older.
The older we get, the faster we get old. I'm not saying that to be cute - it's true, or so I think.
No, we can't transcend time, but - our perception of time changes as we get older. Think about this: Remember being about four or five and thinking about Christmas? Man it took forever to get here!
Now it's more like ... damn, didn't we just do this??
*****
Anyway, use it if it'll help.
The XML is fine and doesn't maintain identity which can be good or bad depending on how you're using it. The time (in History) is written in ticks so that time zone and culture are out of the picture; you don't have to do anything special.
In this case, that's not ever going to be an issue, but just something for future reference:
Dim dt As New DateTime(ticks).
:)
In the middle of difficulty ... lies opportunity. -- Albert Einstein
Monday, May 9, 2016 5:08 PM
Yes I remember as a child my parents saying make the most of it, time goes quicker as you get older and I used to just laugh. But now I am older I can't believe how quick the weeks/years seem to fly by, maybe its just because we are all so much busier nowadays but it is scary
I remember the six week summer school holidays seemed to go on for ever, but now it seems one day they are breaking up for holidays and the next they go back to school again
**********
Oh yes I will definitely make use of it!!!
Okay that make sense re the date as ticks
Darren Rose
Monday, May 9, 2016 5:14 PM
Okay that make sense re the date as ticks
Darren Rose
If you only want the XML to reflect the time in another time zone, you can use a string value that when DateTime parses it, it will reflect the correct time correctly:
dt.ToString("ddd, dd MMM yyyy H:mm:ss zzz")
By including the offset from UTC (GMT), dotNet knows that it needs to modify the value on its end, and it does that well, but if you're crossing cultures - things don't work out so well.
In the US: 4/8/95 would be April 08, 1995 but in some cultures, that would be August 4, 1995.
By keeping it as an actual DateTime - or something that it can use to derive that actual DateTime - it crosses all of those barriers.
With binary, it's persisted as an object that's directly a DateTime, so there's nothing that needs to be done.
I guess that I'm babbling now though. ;-)
In the middle of difficulty ... lies opportunity. -- Albert Einstein
Monday, May 9, 2016 5:21 PM
cool - thanks Frank - very useful as always :)
Darren Rose
Monday, May 9, 2016 5:22 PM
cool - thanks Frank - very useful as always :)
Darren Rose
I'm glad it helped. :)
In the middle of difficulty ... lies opportunity. -- Albert Einstein