Thursday, August 27, 2009

Windows 7 Training Kit for Developers Now Available

Download the new Windows 7 Training Kit for Developers. The kit includes code, videos, and labs for both native Win32 C++ developers and .NET developers covering the new features available in Windows 7.

Click here for more Info...

Wednesday, August 05, 2009

Get Process Status using C#

The following code snippet can be used to get the status of any process or an application given its name or PID (Process ID).

using System.Diagnostics;
private void GetProcessStatus()
{
try
{
//If you know the name of the process
Process[] myProcess = Process.GetProcessesByName("notepad");
//If you know the PID of the process use the commented line below
//Process[] myProcess = Process.GetProcessById("1983");
//Check to see if the process array length is greater than 0
if(myProcess.Length > 0)
{
MessageBox.Show("The Process Notepad is currently running.", "Process Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("The Process Notepad is currently not running.", "Process Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch(Exception ex)
{
MessageBox.Show("An Exception Occoured: " + ex.Message, "Process Status", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

Monday, July 27, 2009

What is AutoEventWireup?

ASP.NET page framework also supports an automatic way to associate page events and methods. If the AutoEventWireup attribute of the Page directive is set to true (or if it is missing, since by default it is true), the page framework calls page events automatically, specifically the Page_Init and Page_Load methods. In that case, no explicit Handles clause or delegate is needed.

The disadvantage of the AutoEventWireup attribute is that it requires that the page event handlers have specific, predictable names. This limits your flexibility in how you name your event handlers. Therefore, in Visual Studio, the AutoEventWireup attribute is set to false by default and the designer generates explicit code to bind page events to methods.

If you do set AutoEventWireup to true, Visual Studio will generate code to bind the events and the page framework will automatically call events based on their names. This can result in the same event code being called twice when the page runs. As a consequence, you should always leave AutoEventWireup set to false when working in Visual Studio.

For more information Click here

Wednesday, July 15, 2009

asp:Menu Server Control - Cross Browser Compatibility (Safari/Chrome)

 

Cross browser compatibility is upsetting while working with asp:Menu Server Control, and It was not rendering/working well with Safari and Chrome.

After bit of googling... :-) and found a solution for this.

Approach 1:

I have added below small piece of code snippet in my MasterPage's Page_Load event

        if (Request.UserAgent.IndexOf("AppleWebKit") > 0)
        {
            Request.Browser.Adapters.Clear();
        }

This will tell asp.net not to use an adapter when rendering the menu control. This will work for both Safari and chrome as well because they both use webkit which is how asp.net identifies.

Approach 2:

You can force the menu to work by overwrite the Page_PreInit method on the page and telling the page that the client target is a modern “uplevel” browser:-

protected void Page_PreInit(object sender, EventArgs e)
{
if (Page.Request.ServerVariables["http_user_agent"].ToLower().Contains("safari"))
{
Page.ClientTarget = "uplevel";
}
}

Unfortunately, you can't just add the fix to your Master Page, it doesn't contain a PreInit method as it's a web control not a web page.

Please note that you have to do this in the page class file, and not in the master page class file. Obviously this means you have to do it for every page – which is not ideal.

Wednesday, May 20, 2009

Date Formats in SQL Server

---Yesterday 
select dateadd(d,-1,getdate()) as yesterday

--First Day of Current Week
select dateadd(wk,datediff(wk,0,getdate()),0) as [First Day of Current Week]

--Last Day of Current Week
select dateadd(wk,datediff(wk,0,getdate()),6) as [Last Day of Current Week]

--First Day of Last Week
select dateadd(wk,datediff(wk,7,getdate()),0) as [First Day of Last Week]

--Last Day of Last Week
select dateadd(wk,datediff(wk,7,getdate()),6) as [Last Day of Last Week]

--First Day of Current Month
select dateadd(mm,datediff(mm,0,getdate()),0) as [First Day of Current Month]

--Last Day of Current Month
select dateadd(ms,- 3,dateadd(mm,0,dateadd(mm,datediff(mm,0,getdate())+1,0))) as [Last Day of Current Month]

--First Day of Last Month
select dateadd(mm,-1,dateadd(mm,datediff(mm,0,getdate()),0)) as [First Day of Last Month]

-- First day of next month
SELECT dateadd(m, datediff(m, 0,getdate())+1, 0) AS MonthStart

-- Last day of next month
SELECT dateadd(m,datediff(m, 0, dateadd(m, +2 ,getdate()))+1, -1) AS MonthEnd

--Last Day of Last Month
select dateadd(ms,-3,dateadd(mm,0,dateadd(mm,datediff(mm,0,getdate()),0))) as [Last Day of Last Month]

--First Day of Current Year
select dateadd(yy,datediff(yy,0,getdate()),0) as [First Day of Current Year]

--Last Day of Current Year
select dateadd(ms,-3,dateadd(yy,0,dateadd(yy,datediff(yy,0,getdate())+1,0))) as [Last Day of Current Year]

--First Day of Last Year
select dateadd(yy,-1,dateadd(yy,datediff(yy,0,getdate()),0)) as [First Day of Last Year]

--Last Day of Last Year
select dateadd(ms,-3,dateadd(yy,0,dateadd(yy,datediff(yy,0,getdate()),0))) as [Last Day of Last Year]

select month('09/06/2008')
select year('09/06/2008')
select getutcdate()
select getdate()
select day('09/06/2008')
select datepart(dd,'09/06/2008')
select datename(yyyy,'09/06/2008')
select datediff(dd,'09/06/2008','09/18/2008')
select dateadd(dd,60,'09/06/2008')