Thursday, December 3, 2009

IIS 7.0 HTTP Error Pages AND The HTTP status codes in IIS 7.0

IIS 7.0 HTTP Error Pages

http://blogs.msdn.com/webtopics/archive/2008/05/28/iis-7-0-http-error-pages.aspx

The HTTP status codes in IIS 7.0

http://support.microsoft.com/kb/943891

Auto Refresh

Method 1: Response.AddHeader

To Refresh Web page After every 5 Seconds You can add following code,

Response.AddHeader("Refresh", "5");

Cricket Sites, Stock Exchange sites use similar logic :)

Method 2: In body Tag, window.setTimeout

The 1000 = 1 Second...

<body onload="window.setTimeout('window.location.reload()',1000);">

Method 3: In Meta Tag

Theres also a meta tag that you can define on the head, but not sure wheter it refreshes even if the content has not finished loading or if it starts counting when the head section loaded. Code would be something like that:

<meta content="600" http-equiv="refresh">

Method 4: Timer Control : Microsoft ASP.NET 2.0 AJAX Extensions server control

In following example, the timer interval is set to 10 seconds

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Timer Example Page</title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
OriginalTime.Text = DateTime.Now.ToLongTimeString();
}

protected void Timer1_Tick(object sender, EventArgs e)
{
StockPrice.Text = GetStockPrice();
TimeOfPrice.Text = DateTime.Now.ToLongTimeString();
}

private string GetStockPrice()
{
double randomStockPrice = 50 + new Random().NextDouble();
return randomStockPrice.ToString("C");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="10000" />

<asp:UpdatePanel ID="StockPricePanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
<ContentTemplate>
Stock price is <asp:Label id="StockPrice" runat="server"></asp:Label><BR />
as of <asp:Label id="TimeOfPrice" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<div>
Page originally created at <asp:Label ID="OriginalTime" runat="server"></asp:Label>
</div>
</form>
</body>
</html>

Tuesday, December 1, 2009

Generating Sequence Number in DataGrid with Paging

There are two ways you can generate sequence number in grid.


1. Generate Sequence Number in Datagrid from aspx page you can simply add:

<%# (DataGrid1.PageSize*DataGrid1.CurrentPageIndex)+ Container.ItemIndex+1%>


2. Generate Sequence Number in Datagrid from SQL:

SELECT ROW_NUMBER() OVER(ORDER BY ID DESC) AS SeqNumber FROM TABLE_NAME

AND Bind DataGrid as,

<%#DataBinder.Eval(Container.DataItem,"SeqNumber")%>

Use for loop in DOS

Example 1.

Register All dlls containing in folder:

Suppose you want to register 100 dlls containg in folder C:\dlls then goto command prompt

SOLUTION:
goto c:\dlls and write command below
for %i in (*.dll) do RegSvr32 -s %i

Example 2.

Print all files containg in folder

SOLUTION:
for %i in (*.*) do echo %i

Tuesday, November 10, 2009

Favicon icon

<link href="favicon.ico" rel="shortcut icon" / >
<link rel="icon" href="favicon.ico" type="image/ico" >

get .ico file from Jpg
---------------------------
http://tools.dynamicdrive.com/favicon/

Tuesday, October 13, 2009

Convert Decimal Amount To Text

public string ConvertToAmountInText(double numberToConvert, bool BlankIfZero, bool ConvertDecimalPart)
{

long Number = (long)numberToConvert;
string strNumberInText = "";

if (Number == 0)
return (BlankIfZero ? "" : "Zero");
else if (Number >= 1 && Number <= 19)
{
string[] numbers = {"One", "Two", "Three", "Four",
"Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven",
"Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen",
"Seventeen", "Eighteen", "Nineteen"};
strNumberInText = numbers[Number - 1];
}
else if (Number >= 20 && Number <= 99)
{
string[] numbers = { "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };
strNumberInText = numbers[Number / 10 - 2] + " " + ConvertToAmountInText(Number % 10, true, false);
}
else if (Number >= 100 && Number <= 999)
{
strNumberInText = ConvertToAmountInText(Number / 100, true, false) + " Hundred " + ConvertToAmountInText(Number % 100, true, false);
}
else if (Number >= 1000 && Number <= 999999)
{
strNumberInText = ConvertToAmountInText(Number / 1000, true, false) + " Thousand " + ConvertToAmountInText(Number % 1000, true, false);
}
else if (Number >= 1000000 && Number <= 999999999)
{
strNumberInText = ConvertToAmountInText(Number / 1000000, true, false) + " Million " + ConvertToAmountInText(Number % 1000000, true, false);
}
else if (Number >= 1000000000)
{
strNumberInText = ConvertToAmountInText(Number / 1000000000, true, false) + " Billion " + ConvertToAmountInText(Number % 1000000, true, false);
}

if (ConvertDecimalPart)
{
double dblDecimalPart = 0.00;
dblDecimalPart = numberToConvert - ((long)numberToConvert);
strNumberInText += " and " + dblDecimalPart.ToString("F").Substring(2) + '/' + Math.Pow(10, dblDecimalPart.ToString("F").Length - 2).ToString();
}

return strNumberInText;
}

Monday, July 20, 2009

C# 4.0: Dynamic Programming



If C# 3.0 was all about Language Integrated Query (LINQ), then C# 4.0 is all about dynamic programming. What exactly does that mean? It means that C# 4.0 brings some of flexibility and declarative style of programming to C#.

But what does that really mean?
To sum it up in one keyword: dynamic.
C# 4.0 is adding a new dynamic keyword which is used as a data type in much the same way the var keyword is used. Why is this important? The biggest reason is that it allows a C# program to use dynamic dispatch to more naturally create objects coming from a dynamic language.
For example, suppose you have a Calculator object declared in C#, meaning it is statically typed. You interact with your object like this:
Calculator calc = GetCalculator();
int sum = calc.Add(10, 20);
That’s pretty simple and straight forward. Now suppose the Calculator is not a statically typed .NET class (or it is a .NET class but you don’t know the specific type of class), you must do something like this:
object calc = GetCalculator();
Type calcType = calc.GetType();
object res = calcType.InvokeMember("Add",
    BindingFlags.InvokeMethod, null,
    new object[] { 10, 20 });
int sum = Convert.ToInt32(res);
That’s not nearly as simple. In fact, it’s downright ugly. There is a lot of non-type-safe calls and reflection going on here that you really shouldn’t have to see.
To take this a step further, if we knew that Calculator was a JavaScript class, you must use similar (but still significantly different) code:
ScriptObject calc = GetCalculator();
object res = calc.Invoke("Add", 10, 20);
int sum = Convert.ToInt32(res);
The reason for the differences in syntax is that there is no unification between the two APIs.
In C# 4.0, you can now use the following syntax:
dynamic calc = GetCalculator();
int sum = calc.Add(10, 20);
If you look at this syntax and the earlier statically typed call, you should notice that the only difference is that in C# we are declaring the data type to be dynamic.

Does this mean that C# is loosing it's roots as a statically typed language or that we should all start moving towards dynamic languages? Absolutely not. What is means is that it is now easier for you to write C# code that talks to objects (or APIs) written in dynamically typed languages. It also means that there is a unified API to talk to any dynamic language. You no longer need to worry about what language you are interoperating with to determine which C# code you must write.
So how does the dynamic keyword work? As I mentioned, it's a keyword in a similar fashion to var. You declare at compile-time the type to be dynamic, but at run-time you get a strongly typed object.

The dynamic keyword is great for writing C# code that consumes a dynamic object, but what about going the other direction and writing C# code that can be called from a dynamic language? You do this by implementing the IDynamicObject interface (or more simply, inheriting from the abstract DynamicObject class) and providing your own implementation for the member lookup and invocation.
Using the features and capabilities of the new dynamic keyword, the IDynamicObject interface, and the fact that the dynamic dispatch can dispatch to both dynamic and static types, C# effectively gets support for duck-typing.


Tuesday, July 14, 2009

Bind CheckedListBox Directly with Datatable in C#

chkListBuilding.Items.Clear();
DataTable dtBuilding = (new BuildingManager()).SelectBuilding();
((ListBox)chkListBuilding).DataSource = dtBuilding;
((ListBox)chkListBuilding).DisplayMember = "BuildingName";
((ListBox)chkListBuilding).ValueMember = "BuildingID";

Check List Box With LINQ + Get Checked IDs Comma Separated

var v = (from b in chkListBuilding.CheckedItems.Cast<listitem>()
select b.Value.ToString());

string BuildingIDs = v.Aggregate(delegate(string item1, string item2)
{
return string.Format("{0}, {1}", item1, item2);
});

Thursday, July 2, 2009

Diffrence Int32.parse, Convert.ToInt32, Int32.TryParse

-------------------Int32.parse(string)-------------------

Int32.Parse (string s) method converts the string representation of a number to its 32-bit signed integer equivalent.
When s is null reference, it will throw ArgumentNullException.
If s is other than integer value, it will throw FormatException.
When s represents a number less than MinValue or greater than MaxValue, it will throw OverflowException.

*******
Example
*******

string s1 = "1234";
string s2 = "1234.65";
string s3 = null;
string s4 = "123456789123456789123456789123456789123456789";

int result;
bool success;

result = Int32.Parse(s1); //-- 1234
result = Int32.Parse(s2); //-- FormatException
result = Int32.Parse(s3); //-- ArgumentNullException
result = Int32.Parse(s4); //-- OverflowException


-------------------Convert.ToInt32(string)-------------------

Convert.ToInt32(string s) method converts the specified the string representation of 32-bit signed integer equivalent. This calls in turn Int32.Parse () method.
When s is null reference, it will return 0 rather than throw ArgumentNullException
If s is other than integer value, it will throw FormatException.
When s represents a number less than MinValue or greater than MaxValue, it will throw OverflowException

*******
Example
*******

result = Convert.ToInt32(s1); //-- 1234
result = Convert.ToInt32(s2); //-- FormatException
result = Convert.ToInt32(s3); //-- 0
result = Convert.ToInt32(s4); //-- OverflowException



-------------------Int32.TryParse(string, out int)------------------

Int32.Parse(string, out int) method converts the specified the string representation of 32-bit signed integer equivalent to out variable, and returns true if it parsed successfully, false otherwise. This method is available in C# 2.0
When s is null reference, it will return 0 rather than throw ArgumentNullException.
If s is other than integer value, the out variable will have 0 rather than FormatException.
When s represents a number less than MinValue or greater than MaxValue, the out variable will have 0 rather than OverflowException.

*******
Example
*******

success = Int32.TryParse(s1, out result);
//-- success => true; result => 1234
success = Int32.TryParse(s2, out result);
//-- success => false; result => 0
success = Int32.TryParse(s3, out result);
//-- success => false; result => 0
success = Int32.TryParse(s4, out result);
//-- success => false; result => 0

Convert.ToInt32 is better than Int32.Parse, since it return 0 rather than exception. But, again according to the requirement this can be used. TryParse will be best since it handles exception itself always.

Tuesday, June 30, 2009

Find Average from datatable column using LINQ and Compute Method

--Using LINQ

var v = (from o in dt.Rows.Cast()
select o.Field("Grand Total")).Average();

--Using Datatable Compute Method

Object objAvg;
objAvg = dt.Compute("Avg([Grand Total])", "[Grand Total] > 0");

--Find Standard Deviation using Datatable Compute method

Object objStDev;
objStDev = dt.Compute("StDev([Grand Total])", "[Grand Total] > 0");

Thursday, June 11, 2009

Regualr expressions for password

Regular expression for Password must be 8 or more characters long, including a capital letter and a number or symbol.

^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=\d]).*$


Regular expression for Password must be 8 or more characters long, including a capital letter and a number and symbol.

^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$


Like wise you can create your own Regular expression.

Monday, May 25, 2009

Enable/Disable Link Button in Java script on Checked Changed Event

<asp:CheckBox ID="chkPermission" runat="server"
Text="I have permission / rights to upload these files and use it in public."
AutoPostBack="false" OnClick="JavaScript:EnableDisableSaveFile();" />


<asp:LinkButton ID="lbtnSaveFiles" runat="server"
Text="Save Files" OnClick="lbtnSaveFiles_Click"
Enabled="true"></asp:LinkButton>


<script type="text/javascript">

function EnableDisableSaveFile()
{

var checked=document.getElementById('<%= chkPermission.ClientID %>').checked;
document.getElementById('<%= lbtnSaveFiles.ClientID %>').disabled = !checked;
document.getElementById('<%= lbtnSaveFiles.ClientID %>').onclick =
function() { return checked };

}

</script>