Saturday, October 16, 2010

How to Enable CLR integration in SQL Server

This code segment explain you, How to Enable CLR integration in SQL Server using TSQL

To enable CLR integration in SQL Server, Use follwing TSQL statment.



EXEC sp_configure 'clr enabled', 1;

RECONFIGURE WITH OVERRIDE;

GO;



similarly for Disabling use follwing.



EXEC sp_configure 'clr enabled', 0;

RECONFIGURE WITH OVERRIDE;

GO ;

Thursday, October 14, 2010

C# code for Lock windows

This simple code segment explain you, How to lock windows using C# code (same as pressing Windows logo key and the letter L)




This is nothing but calling of “C:\WINDOWS\system32\rundll32.exe user32.dll, LockWorkStation” command from C#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;


namespace Sajid.LockComputer

{

class Program
{
static void Main(string[] args)
{
Process.Start(@"C:\WINDOWS\system32\rundll32.exe", "user32.dll,LockWorkStation") ;
}
}
}

XML to HTML transformation using Xslt

Namespace Required:

1. System.Xml
2. System.Xml.XPath
3. System.Xml.Xsl

public static void Transform(string sXmlPath, string sXslPath)

{

try

{

// Step 1: load the Xml doc

XPathDocument myXPathDoc = new XPathDocument(sXmlPath) ;

XslTransform myXslTrans = new XslTransform() ;



// Step 2: load the Xsl

myXslTrans.Load(sXslPath) ;



// Step 3: create the output stream



XmlTextWriter myWriter = new XmlTextWriter("result.html", null);



// Step 4: do the actual transform of Xml





myXslTrans.Transform(myXPathDoc,null, myWriter);

myWriter.Close() ;

}

catch(Exception e)

{

Console.WriteLine("Exception: {0}", e.ToString());

}

}

Change SQL Server Authentication Mode Using TSQL

We can use undocumented procedure xp_regwrite/xp_instance_regwrite, to change the authentication mode form query.


exec master..xp_instance_regwrite N'HKEY_LOCAL_MACHINE',N'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer','LoginMode', N'REG_DWORD', 2

0 or 2 => Mixed Mode

1 => integrated

Wednesday, October 13, 2010

How to Format A Excle Column.

Summary : This Code Code Snippets Guide you to format EXCEL Column progrmaticaly. Here i am doing number formating

Follwing is the COde for formating the first Column of EXcel sheet. You Have to change the Column index of cell to format the required column

VB.NET

Dim Wb As Excel.Workbook =
Dim xWS As Excel.Worksheet
xWS = Wb.ActiveSheet
CType(xWS.Cells(1, 1), Excel.Range).EntireColumn.NumberFormat = "#,##0.00"

C#


Excel.Workbook wb = ;
Excel.Worksheet xWS;
xWS = wb.ActiveSheet;
Excel.Range rng = xWS.Cells[1,1] as Excel.Range;
rng.EntireColumn.NumberFormat = "#,##0.00";

Tuesday, October 12, 2010

5 Traps to Avoid in C#

C# Corner columnist Patrick Steele offers a heads up on five gotchas that can trip up even veteran C# programmers. This is Very usefull for C# programmers

Clik here to view the post

Monday, October 11, 2010

How to Convert Image to Binary String?

Here you will learn How Convert Image to Binary String using of C# and the .NET Framework.

Basically, the program "reads" the image pixel by pixel, and where there is a pixel that is something else than white it will Append 1, else 0 in the string.

private string ConvertoToString(string imagePath)
{
string text = "";
System.Drawing.Bitmap bitMap = new Bitmap(imagePath);
for (int i = 0; i < bitMap.Height; i++)
{
for (int j = 0; j < bitMap.Width; j++)
{
if (bitMap.GetPixel(j, i).A.ToString() == "255" && bitMap.GetPixel(j, i).B.ToString() == "255" && bitMap.GetPixel(j, i).G.ToString() == "255" && bitMap.GetPixel(j, i).R.ToString() == "255")
{
text = text + "0";
}
else
{
text = text + "1";
}
}
text = text + "";
}
return ( text);
}