Import
Import.aspx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <%@ Control Language="vb" AutoEventWireup="false" Codebehind="Import.ascx.vb" Inherits="DamianM.Import" %> <form id="Form1" method="post" runat="server"> <h2>Example Imported Bookmark</h2> <asp:datalist id="dlBM" runat="server" EnableViewState="false" ItemStyle-Font-Name="Georgia" CellPadding="10" CellSpacing="5" ItemStyle-Wrap="true" BorderWidth="1" BackColor="GhostWhite" AlternatingItemStyle-BackColor="WhiteSmoke"> <ItemTemplate> <strong><a href='<%# DataBinder.Eval(Container.DataItem, "href") %>'> <%# DataBinder.Eval(Container.DataItem, "Title") %> </a></strong> <br> Folder :<%# DataBinder.Eval(Container.DataItem, "Folder") %> <br> Created :<%# DataBinder.Eval(Container.DataItem, "add_date") %> <br> Modified :<%# DataBinder.Eval(Container.DataItem, "last_modified") %> <br> Last Used :<%# DataBinder.Eval(Container.DataItem, "last_visit") %> </ItemTemplate> </asp:datalist> </form> |
Import.aspx.vb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | Public MustInherit Class Import Inherits System.Web.UI.UserControl Protected WithEvents dlBM As System.Web.UI.WebControls.DataList Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load ' get the bookmark file into a string Dim s As New System.IO.StreamReader(Server.MapPath("/code/3/bookmark.htm")) Dim bmrk As String bmrk = s.ReadToEnd s.Close() 'set up reqular expression and get matches Dim r As New System.Text.RegularExpressions.Regex("(HREF=""(?<href>[^""]+)""[\w\W]*?ADD_DATE=""(?<add_date>[^""]+)""[\w\W]*?LAST_VISIT=""(?<last_visit>[^""]+)""[\w\W]*?LAST_MODIFIED=""(?<last_modified>[^""]+)""[\w\W]*?>(?<title>[^<]+)<)|(<H3[\w\W]*?>(?<folder>[^<]+)<)|(</DL>(?<back>[^p]+)p>)") Dim ms As System.Text.RegularExpressions.MatchCollection = r.Matches(bmrk) 'create holder for invidiular matches Dim m As System.Text.RegularExpressions.Match 'create date time variable set to 1/1/1970. the start date for bookmark dates and times Dim dt As New System.DateTime(1970, 1, 1) 'create timespan to hold times from bookmark file Dim ts As New System.TimeSpan() 'create holding table Dim dtbl As New System.Data.DataTable("BookMarks") dtbl.Columns.Add("Folder") dtbl.Columns.Add("title") dtbl.Columns.Add("href") dtbl.Columns.Add("add_date") dtbl.Columns.Add("last_visit") dtbl.Columns.Add("last_modified") Dim rw As System.Data.DataRow Dim path As String = "\" 'loop through matches filling out table For Each m In ms ' if the folder match is not empty add it to the path If m.Groups("folder").Value <> "" Then path += m.Groups("folder").Value + "\" End If ' if the back match if not empty remove the last directory on the path If m.Groups("back").Value <> "" Then path = path.Substring(0, path.LastIndexOf("\")) path = path.Substring(0, path.LastIndexOf("\") + 1) End If 'if title is not empty fill out record If m.Groups("title").Value <> "" Then rw = dtbl.NewRow() rw("Folder") = path rw("title") = m.Groups("title").Value rw("href") = m.Groups("href").Value 'convert time in seconds from bookmark file into ticks ( 100 nano seconds) ts = New System.TimeSpan(Convert.ToDouble(m.Groups("add_date").Value) * 10000000) 'add elapsed time to base date rw("add_date") = dt.Add(ts) 'convert time in seconds from bookmark file into ticks ( 100 nano seconds) ts = New System.TimeSpan(Convert.ToDouble(m.Groups("last_visit").Value) * 10000000) 'add elapsed time to base date rw("last_visit") = dt.Add(ts) 'convert time in seconds from bookmark file into ticks ( 100 nano seconds) ts = New System.TimeSpan(Convert.ToDouble(m.Groups("last_modified").Value) * 10000000) 'add elapsed time to base date rw("last_modified") = dt.Add(ts) dtbl.Rows.Add(rw) End If Next 'display results dlBM.DataSource = dtbl dlBM.DataBind() End Sub End Class |



















