Thursday, June 3, 2010

Disable content copy using java script

You can prevent copy of content from your page by using following java script:


document.oncontextmenu = function() { alert("Copy not allowed"); return false; }
window.onload = function() {
document.onselectstart = function() { return false; } // ie
document.onmousedown = function() { return false; } // mozilla
}


If you want to disable copy for perticular element you can use following java script

window.onload = function() {
var element = document.getElementById('content');
element.onselectstart = function () { return false; } // ie
element.onmousedown = function () { return false; } // mozilla
}

Tuesday, March 9, 2010

LINQ let Keyword

How can I miss that! :)

I have been working with LINQ for almost 2 years, and I've never noticed the new keyword "let" which is used inside LINQ queries to create temporarily variables.

var list = new List() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var query = from i in list
let j = i + 2
let k = j * j
select new { i, j, k };

You can see the let keyword was used to create two new temp variables (j, k) which their values were calculated inside the query.

Looks nice, doesn't it!!

Could not load file or assembly or one of its dependencies. Access is denied" Error

Recently, I have installed Windows7 and configured one project from my friend's pc on my machine and I have faced this problem.

I have found solutions that works are,

Go to "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files" ( Modify the framework version, root directory etc according to your environment.)

Now, right-click and open up the Security tabs for this folder. Grant "Full control" to the 'users' group. However, it this is a security problem for your environment to grant full control to all users in Users group

If you don't find this folder, you need to register ASP.NET on IIS.
You can do so by opening VS Command promot and type aspnet_regiis.exe -i

Another Solution could be to put the concerned assemblies lo GAC.

I think this problem exists for pcs with fresh installation.

Monday, February 1, 2010

lock and unlock your folder with this simple trick !

You can lock and unlock your folder with this simple trick !

Procedure :
1. Make a folder on the desktop and name it as "folder"

2. Now, open notepad and write ren folder folder.{21EC2020-3AEA-1069-A2DD-08002B30309D} and now (Notepad Menu) File>save as.

3. In the 'save as' name it as lock.bat and click save ! (Save it on Desktop)

4. Now, again open notepad again and write ren folder.{21EC2020-3AEA-1069-A2DD-08002B30309D} folder and now (Notepad Menu) File>save as.

5. In the 'save as' name it as key.bat and click save ! (Save it on Desktop)

6. Now, double click lock.bat to lock the folder and now if you open your folder, control panel will open up !

7. Now, double click key.bat to open the folder and now if you open your folder, you can access your data inside the folder again !

8. Lock your folder and hide the key.bat somewhere else on your hard disk !

9. Whenever you want to open your folder just paste the key.bat on desktop and open your folder using it !

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;
}