
This blog is for .NET and related web technology, where you will find some really good and time saving answers which can help you to make your fundaas clear.
Friday, January 7, 2011
Friday, September 24, 2010
Convert HTML table to DataSet while downloading data from another site
Convert HTML table to DataSet while downloading data from another site
Just imagine a situation while you are downloading the data from another site using
System.Net.WebClient client = new System.Net.WebClient();
string st = client.DownloadString(strURL);
or directly if you find a HTML table there and you want to add that table to dataset for further processing.this function will help you for that using regular expressions.
private DataSet ConvertHTMLTablesToDataSet(String HTML)
{
DataSet ds = new DataSet();
try
{
DataTable dt = new DataTable();
DataRow dr;
DataColumn dc;
string TableExpression = "<table[^>]*>(.*?)</table>";
string HeaderExpression = "<th[^>]*>(.*?)</th>";
string RowExpression = "<tr[^>]*>(.*?)</tr>";
string ColumnExpression = "<td[^>]*>(.*?)</td>";
bool HeadersExist = false;
int iCurrentColumn = 0;
int iCurrentRow = 0;
//Get a match for all the tables in the HTML
MatchCollection Tables = Regex.Matches(HTML, TableExpression, RegexOptions.IgnoreCase);
//Loop through each table element
foreach (Match Table in Tables)
{
// Reset the current row counter and the header flag
iCurrentRow = 0;
HeadersExist = false;
//Add a new table to the DataSet
dt = new DataTable();
// Create the relevant amount of columns for this table (use the headers if they exist, otherwise use default names)
if (Table.Value.ToString().Contains("<th"))
{
// Set the HeadersExist flag
HeadersExist = true;
// Get a match for all the rows in the table
MatchCollection Headers = Regex.Matches(Table.Value, HeaderExpression, RegexOptions.IgnoreCase);
// Loop through each header element
foreach (Match Header in Headers)
{
dt.Columns.Add(Header.Groups[1].ToString());
}
}
else
{
for (int iColumns = 1; iColumns <= Regex.Matches(Regex.Matches(Regex.Matches(Table.Value, TableExpression, RegexOptions.IgnoreCase)[0].Value.ToString(), RowExpression, RegexOptions.IgnoreCase)[0].Value.ToString(), ColumnExpression, RegexOptions.IgnoreCase).Count; iColumns++)
{
dt.Columns.Add("Column " + iColumns);
}
}
//Get a match for all the rows in the table
MatchCollection Rows = Regex.Matches(Table.Value, RowExpression, RegexOptions.IgnoreCase);
//Loop through each row element
foreach (Match Row in Rows)
{
//Only loop through the row if it isn't a header row
if (!(iCurrentRow == 0 && HeadersExist == true))
{
//Create a new row and reset the current column counter
dr = dt.NewRow();
iCurrentColumn = 0;
// Get a match for all the columns in the row
MatchCollection Columns = Regex.Matches(Row.Value, ColumnExpression, RegexOptions.IgnoreCase);
// Loop through each column element
foreach (Match Column in Columns)
{
//Add the value to the DataRow
dr[iCurrentColumn] = Column.Groups[1].ToString();
//Increase the current column
iCurrentColumn += 1;
}
dt.Rows.Add(dr);
//Add the DataRow to the DataTable
}
// Increase the current row counter
iCurrentRow += 1;
}
// Add the DataTable to the DataSet
ds.Tables.Add(dt);
}
}
catch { }
finally { }
return ds;
}
Numeric Paging with asp.net menu control
Paging with asp.net menu control
Just pass the total number of records, currently displayed record and menu control.if you want to display like 10 number for paging.If i select page number 15 this will fill the menu from 10 to 20 etc.
i.e.
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
12 13 14 15 16 17 18 19 20 21
public void fillmenu(int tot, int value, Menu menu)
{
if (tot > 100)
{
int page_count = 0;
if (tot % 10 == 0)
page_count = tot / 10;
else
page_count = tot / 10 + 1;
if (menu.SelectedValue == "" || menu.SelectedValue == null)
{
menu.Items.Clear();
for (int i = 1; i <= 10; i++)
{
string text = "";
if (i == value)
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
mi.Selected = true;
menu.Items.Add(mi);
}
else
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
menu.Items.Add(mi);
}
MenuItem mi1 = new MenuItem(text, i.ToString());
menu.Items.Add(mi1);
}
menu.Items.Add(new MenuItem(".....", ""));
menu.Items[10].Selectable = false;
MenuItem mi3 = new MenuItem((page_count).ToString(), (page_count).ToString());
menu.Items.Add(mi3);
}
else
{
if (Convert.ToInt32(menu.SelectedValue) <= 5)
{
}
else if (value > page_count - 5)
{
menu.Items.Clear();
for (int i = page_count - 10; i <= page_count; i++)
{
string text = "";
if (value == i)
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
mi.Selected = true;
menu.Items.Add(mi);
}
else
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
menu.Items.Add(mi);
}
}
}
else
{
int sel = Convert.ToInt32(menu.SelectedValue);
menu.Items.Clear();
for (int i = sel - 4; i <= sel + 5; i++)
{
string text = "";
if (value == i)
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
mi.Selected = true;
menu.Items.Add(mi);
}
else
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
menu.Items.Add(mi);
}
}
menu.Items.Add(new MenuItem(".....", ""));
menu.Items[10].Selectable = false;
MenuItem mi2 = new MenuItem((page_count).ToString(), (page_count).ToString());
menu.Items.Add(mi2);
}
}
}
else
{
menu.Items.Clear();
for (int i = 1; i <= tot / 10 + 1; i++)
{
string text = "";
if (i == value)
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
mi.Selected = true;
menu.Items.Add(mi);
}
else
{
text = i.ToString();
MenuItem mi = new MenuItem(text, i.ToString());
menu.Items.Add(mi);
}
}
}
}
Clear all values of textbox and checkbox from a particular asp.net page
Make the asp.net controls clear
If you want to clear the asp.net controls like textbox and textbox.
This function clears whole occurence of the the defined controls.
Just past the Varaible parent as 'this' , which will clear the whole controls from that particular page which are defined in this function.
public void ClearControls(Control parent)
{
foreach (Control _ChildControl in parent.Controls)
{
if ((_ChildControl.Controls.Count > 0))
{
ClearControls(_ChildControl);
}
else
{
if (_ChildControl is TextBox)
{
((TextBox)_ChildControl).Text = string.Empty;
}
else
if (_ChildControl is CheckBox)
{
((CheckBox)_ChildControl).Checked = false;
}
}
}
}
Image Resizing in asp.net c#
Resizing the image in asp.net C#
This is a very simple example for image resizing while uploading through fileupload control.//OriginalFile - Path for the original image
//NewFile - Path for the New image
//NewWidth - Define new width
//MaxHeight - Define MAX Height
//OnlyResizeIfWider - True if you want to resize images which have greater dimensions from defined new dimensions.
public void ResizeImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
{
System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFile);
// Prevent using images internal thumbnail
FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
if (OnlyResizeIfWider)
{
if (FullsizeImage.Width <= NewWidth)
{
NewWidth = FullsizeImage.Width;
}
}
int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;
if (NewHeight > MaxHeight)
{
// Resize with height instead
NewWidth = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;
NewHeight = MaxHeight;
}
System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);
// Clear handle to original file so that we can overwrite it if necessary
FullsizeImage.Dispose();
// Save resized picture
NewImage.Save(NewFile);
}
Thursday, September 16, 2010
ASP ServerVariables Collection
ASP ServerVariables Collection
The ServerVariables collection is used to retrieve the server variable values.
Syntax
Request.ServerVariables (server_variable) |
Parameter | Description |
---|---|
server_variable | Required. The name of the server variable to retrieve |
Server Variables
Variable | Description |
---|---|
ALL_HTTP | Returns all HTTP headers sent by the client. Always prefixed with HTTP_ and capitalized |
ALL_RAW | Returns all headers in raw form |
APPL_MD_PATH | Returns the meta base path for the application for the ISAPI DLL |
APPL_PHYSICAL_PATH | Returns the physical path corresponding to the meta base path |
AUTH_PASSWORD | Returns the value entered in the client's authentication dialog |
AUTH_TYPE | The authentication method that the server uses to validate users |
AUTH_USER | Returns the raw authenticated user name |
CERT_COOKIE | Returns the unique ID for client certificate as a string |
CERT_FLAGS | bit0 is set to 1 if the client certificate is present and bit1 is set to 1 if the cCertification authority of the client certificate is not valid |
CERT_ISSUER | Returns the issuer field of the client certificate |
CERT_KEYSIZE | Returns the number of bits in Secure Sockets Layer connection key size |
CERT_SECRETKEYSIZE | Returns the number of bits in server certificate private key |
CERT_SERIALNUMBER | Returns the serial number field of the client certificate |
CERT_SERVER_ISSUER | Returns the issuer field of the server certificate |
CERT_SERVER_SUBJECT | Returns the subject field of the server certificate |
CERT_SUBJECT | Returns the subject field of the client certificate |
CONTENT_LENGTH | Returns the length of the content as sent by the client |
CONTENT_TYPE | Returns the data type of the content |
GATEWAY_INTERFACE | Returns the revision of the CGI specification used by the server |
HTTP_<HeaderName> | Returns the value stored in the header HeaderName |
HTTP_ACCEPT | Returns the value of the Accept header |
HTTP_ACCEPT_LANGUAGE | Returns a string describing the language to use for displaying content |
HTTP_COOKIE | Returns the cookie string included with the request |
HTTP_REFERER | Returns a string containing the URL of the page that referred the request to the current page using an <a> tag. If the page is redirected, HTTP_REFERER is empty |
HTTP_USER_AGENT | Returns a string describing the browser that sent the request |
HTTPS | Returns ON if the request came in through secure channel or OFF if the request came in through a non-secure channel |
HTTPS_KEYSIZE | Returns the number of bits in Secure Sockets Layer connection key size |
HTTPS_SECRETKEYSIZE | Returns the number of bits in server certificate private key |
HTTPS_SERVER_ISSUER | Returns the issuer field of the server certificate |
HTTPS_SERVER_SUBJECT | Returns the subject field of the server certificate |
INSTANCE_ID | The ID for the IIS instance in text format |
INSTANCE_META_PATH | The meta base path for the instance of IIS that responds to the request |
LOCAL_ADDR | Returns the server address on which the request came in |
LOGON_USER | Returns the Windows account that the user is logged into |
PATH_INFO | Returns extra path information as given by the client |
PATH_TRANSLATED | A translated version of PATH_INFO that takes the path and performs any necessary virtual-to-physical mapping |
QUERY_STRING | Returns the query information stored in the string following the question mark (?) in the HTTP request |
REMOTE_ADDR | Returns the IP address of the remote host making the request |
REMOTE_HOST | Returns the name of the host making the request |
REMOTE_USER | Returns an unmapped user-name string sent in by the user |
REQUEST_METHOD | Returns the method used to make the request |
SCRIPT_NAME | Returns a virtual path to the script being executed |
SERVER_NAME | Returns the server's host name, DNS alias, or IP address as it would appear in self-referencing URLs |
SERVER_PORT | Returns the port number to which the request was sent |
SERVER_PORT_SECURE | Returns a string that contains 0 or 1. If the request is being handled on the secure port, it will be 1. Otherwise, it will be 0 |
SERVER_PROTOCOL | Returns the name and revision of the request information protocol |
SERVER_SOFTWARE | Returns the name and version of the server software that answers the request and runs the gateway |
URL | Returns the base portion of the URL |
Friday, September 10, 2010
Table of SQL Keywords and Descriptions
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Extended Binary-Coded Decimal Interchange Code(EBCDIC)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Table of Delphi keywords and Descriptions
Table of Delphi keywords and Descriptions
|
Table of C# keywords and Descriptions
C# Keywords Table
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|