Sunday, March 18, 2007

Apply Unicode in your website

1. To install Unicode into you Web page, you need to add the underlined lines in your HEAD section:
<html>
<head>
<title> Your Web page Title </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
</head>
2. In the BODY section, to display Unicode font as you like it, you need to add <font face="xxxxx" ......> in which xxxxx is one of Unicode names as following: Arial, Courier News, Tahoma, Times New Roman and Verdana. Moreover, you must convert your text into Unicode format to paste them in the content of your web page.
<body>
<font face="Arial" size="5"> இது தமிழ் மொழி </font>
</body>
</html>

What is RegEx (Regular Expression) ?


Regular expressions are a language that can be used to explicitly describe patterns within strings of text. In addition to simply describing such patterns, regular expression engines can typically be used to iterate through matches, to parse strings into substrings using patterns as delimiters, or to replace or reformat text in an intelligent fashion. They provide a powerful and usually very succinct way to solve many common tasks related to text manipulation.

Quantifiers

1. *, which describes "0 or more occurrences"
2. +, which describes "1 or more occurrences"
3. ?, which descirbes "0 or 1 occurrence

Explicit quantifiers use curly braces {} and number values for upper and lower occurrence limits within the braces.
eg:
ab{2}c abbc, aaabbccc

for more details please visit the following url
http://msdn2.microsoft.com/en-us/library/ms972966.aspx

Need more examples visit http://www.regular-expressions.info/
Get Client Machine IP Address


string strIP= Request.ServerVariables["REMOTE_ADDR"]

string strIP1= Request.UserHostAddress;

Wednesday, March 14, 2007

Resize an Array (ASP.NET)



Following example describes how to resize an array

Dim str(10) As String

str(0) = "a"
str(1) = "b"
str(2) = "c"
str(3) = "d"
Response.Write(UBound(str) & "<br>")
Array.Resize(str, 4)
Response.Write(UBound(str) & "<br>")
Run a batch file through ASP.NET


This is a sample program for running a batch file using asp.net


Imports System.Diagnostics

Partial Class testing
Inherits System.Web.UI.Page

Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p As New ProcessStartInfo
p.WorkingDirectory = "c:\"
p.FileName = "p.bat"
p.UseShellExecute = True
Process.Start(p)
End Sub
End Class

Create "p.bat" and a.txt file in C directory and "p.bat" file contains the following code

ren a.txt b.txt
pause
Email validation Using ASP.NET

Dim strRegexEmail As String = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" & _
"\.[0-9]{1,3}\.[0-9]{1,3}\.)(([a-zA-Z0-9\-]+\" & _
".)+))([a-zA-Z]{2,4}[0-9]{1,3})(\]?)$"

Dim re As New Regex(strRegexEmail)


If Not re.IsMatch(txtEmail.Text) And Trim(txtEmail.Text) <> "" Then
ClientErrorMSG = "Email Address is Invalid"
txtEmail.Focus()
End If

Getting Error '0.cells' is null or not an object, when menu is inside of UpdatePanel


Keep menu outside of update panel and configure the trigger property as the following example code.


<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Menu1" EventName="MenuItemClick" />
</Triggers>
</asp:UpdatePanel>

<asp:Menu ID="Menu1" runat="server" BackColor="#F7F6F3" DynamicHorizontalOffset="2"
Font-Names="Verdana" Font-Size="Small" ForeColor="#7C6F57" OnMenuItemClick="Menu1_MenuItemClick"
StaticSubMenuIndent="10px" Width="150px">
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicHoverStyle BackColor="#7C6F57" ForeColor="White" />
<DynamicMenuStyle BackColor="#F7F6F3" />
<StaticSelectedStyle BackColor="#5D7B9D" />
<DynamicSelectedStyle BackColor="#5D7B9D" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<Items>
<asp:MenuItem Text="Save" Value="Save"></asp:MenuItem>
<asp:MenuItem Text="New" Value="New"></asp:MenuItem>
</Items>

Monday, March 12, 2007

Retrieve and Insert Multiple DataTable into a DataSet (ASP.NET)




You can do it as following way

Public Function GenerateData(strCity as String, strState as String, Rural1 As String ) As DataSet
Dim dt As New DataTable("S1")
Dim dtData As New DataTable("S2")

Dim dr As DataRow
Dim ds As New DataSet

dt.Columns.Add("City", System.Type.GetType("System.String"))
dt.Columns.Add("State", System.Type.GetType("System.String"))
......


dtData.Columns.Add("Data1", System.Type.GetType("System.String"))
dtData.Columns.Add("Mile1", System.Type.GetType("System.String"))
......

dr = dt.NewRow
dr.Item("City") = strCity
dr.Item("State") = strState
......

dt.Rows.Add(dr)

dr = dtData.NewRow
dr.Item("Data1") = "Rural Population"
dr.Item("Mile1") = Rural1
.......

dtData.Rows.Add(dr)

ds.Tables.Add(dt)

ds.Tables.Add(dtData)

GenerateData=ds
ds=Nothing
End Function

Dim ds as New DataSet


ds=GenerateData(..., ..., ...)

Grid1.DataSource= ds.Tables("S1")
Grid2.DataSource= ds.Tables("S2")
Web Scraping Using ASP.NET



Private Function ScrapeHTML(ByVal strURL As String) As String

Dim objWebRequest As System.Net.HttpWebRequest
Dim objWebResponse As System.Net.HttpWebResponse
Dim streamReader As System.IO.StreamReader

Try
objWebRequest = CType(System.Net.WebRequest.Create(strURL), System.Net.HttpWebRequest)
objWebRequest.Method = "GET"
objWebResponse = CType(objWebRequest.GetResponse(), System.Net.HttpWebResponse)
streamReader = New System.IO.StreamReader(objWebResponse.GetResponseStream)
strHTML = streamReader.ReadToEnd
ScrapeHTML = strHTML
Catch ex1 As Exception

ScrapeHTML = strHTML

End Try


End Function

The Return value of the scrapeHTML hold the HTML String output of the given URL.

Do further string comparison to make your own stuffs. :)
Remove Horizontal Scrollbar in IFRAME



Remove the following line from your HTML Page

< ! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >


So your IFRAME won't show the Horizontal Scrollbars :)