Google


Earn money without investing 1$

lovebird-mails.com lovebird-mails.com

Wednesday, August 8, 2007

what is user control?

These are like .aspx pages.The extension is .ascx.It supports caching mechanism in the project.We can also create our own user control and add them in the tool box as how we have in our toolbox.

Urgent Variable in SSIS package?

How to use global variable in Microsoft SSIS (DTS) package

http://www.codeproject.com/useritems/global_variable_in_SSIS.asp

y autoeventwireup attribute will be set to false?

http://www.codeproject.com/aspnet/AutoEventWireup.asp

what is the major difference between 1.1 an 2.0?

http://msdn2.microsoft.com/en-us/library/t357fb32(VS.80).aspx

Difference between Cloning and Copying(Very Important)

Copy will copy the structre as well as Data to another object.

Clone will create a copy of that structure with default values.
class object{
public int i = 0;
public object(){
}
}

Object ob1 = new Object();
ob1.i = 4;
Response.write(ob1.i);//Result 4
Object ob2 = ob1;
Response.write(ob2.i);//Result 4
Object ob3 = ob1.clone();
Response.write(ob3.i);//Result 0.

How to use Query string in our program?

webform1.aspx?id="+somevalue what u want to send+";

It is seen in the url when u redirect to other page.It is seen in the url of the site.
To store the querystring u have write some code in the page itself as mentioned below
string str = QueryString["id"];

Download XML notepad

Download XML notepad from here

http://www.microsoft.com/downloads/details.aspx?FamilyID=72d6aa49-787d-4118-ba5f-4f30fe913628&DisplayLang=en

Some useful javascript function using regular expression

Most of the time we require to validate the control in the client side using javascript.Below are some useful function


For removing blank spaces with regular Expression-----------------------

function trimAll(value)
{
var temp = value;
var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
if (obj.test(temp))
{
temp = temp.replace(obj, '$2');
}
var obj = / +/g;
temp = temp.replace(obj, " ");
if (temp == " ")
{
temp = "";
}
return temp;
}

For Zip code validation US Zip Code------------------------------------------

function isValidZipCode(val)
{
var exp=/(^\d{5}$)(^\d{5}-\d{4}$)/;
var re = new RegExp(exp);
return (val.match(re));
}

For checking Alphanumeric value-----------------------------------
function CheckAlphanumeric (e)
{
var key;
key = e.which ? e.which : e.keyCode;
if((key>=48 &&amp; key<=57)(key>=65 && key<=91) (key >=97 && key<=123)) {
e.returnValue= true;
}
else
{
alert("please enter Alphanumeric only");
e.returnValue = false;
}
}
Time in 12 hour foramt-----------------------------------------------

function validateTime(strValue,state)
{
var objRegExp = /^([1-9]1[0-1]):[0-5]\d(:[0-5]\d(\.\d{1,3})?)?$/;
if(!(objRegExp.test( strValue )))
{
alert("Please Enter "+ state +" time in 12 hour format eg 11:30 ");
}
return objRegExp.test( strValue );
}

Hope this will help all

Namespace in c#

Namespace

C# namespace allow us to organize our class.unlike a file and component namespace provide us a flexibility to group our class and other types
For eg
Namespace MyCustomNameSpace
{
using System;
public int show()
{
return 0;
}
}
Using keyword in C#
C# allows us to abbreviate a class full name for doing this we have to list the class namespace at the top of the file with the “Using” key word
Eg
Using MyNameSpace.CsharpExample
Class MyClass
{
public static int Main()
{
SomeOtherNameSpace.SomeOtherClass loMyObj = new SomeOtherNameSpace.SomeOtherClass loMyObj();
Return 0;
}
}
Namespace Aliases
The another use of the namespace in c# is creating aliases.this is use ful when we have a long namespace for eg
Using myAliases = MyNameSpace.CsharpExample;

Easier way to add a DLL to the GAC

To quickly add assemblies to the GAC - a registry key can be created
which allows you to right click the DLL and 'GAC it' in one click.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\dllfile\shell\gacutil\command]
@="c:\\windows\\Microsoft.NET\\Framework\\v1.1.4322\\gacutil.exe /i
\"%1\""

Reference link
http://markharrison.co.uk/blog/2005/12/easier-way-to-add-dll-to-gac.htm

Check Valid user using LDAP

The below function will authenticate user using Active Directory.


public bool IsAuthenticated(string domain, string username, string pwd)

{

string _path;

string _filterAttribute;

string servername = "ServerName"; // Give the server Name

string domainAndUsername = domain + "\\" + username;

DirectoryEntry entry = new DirectoryEntry("LDAP://" + servername, domainAndUsername, pwd);

try

{

object obj = entry.NativeObject;

DirectorySearcher search = new DirectorySearcher(entry);

search.Filter = "(SAMAccountName=" + username + ")";

search.PropertiesToLoad.Add("cn");

SearchResult result = search.FindOne();

if (result == null)

{

return false;

}

_path = result.Path;

_filterAttribute = ((string)(result.Properties["cn"][0]));

}

catch (Exception ex)

{

return false;

}

return true;

}

Convert string to byte array and vice-versa

This code sample shows how to convert a string to a byte array and and byte array to string.

//function to convert string to byte array
public static byte[] ConvertStringToByteArray(string stringToConvert)
{
return (new UnicodeEncoding()).GetBytes(stringToConvert);
}

//function to convert byte array to string
public static string ConvertByteArrayToString(byte[] byteArray)
{
return (new UnicodeEncoding()).GetString(byteArray);
}

Random number generator function in c#

Hi All,
Some time we need to generate random sequence of alphanumeric /nemeric/character for password/key etc. Below is static function which takes integer as parameter for the length of the output.

private static string RandomNumberGenerator(int length)
{
RandomNumberGenerator rng = RandomNumberGenerator.Create();
char[] chars = new char[length];
string validChars = "abcdefghijklmnopqrstuvwxyzABCEDFGHIJKLMNOPQRSTUVWXYZ1234567890"; //based on your requirment you can take only alphabets or number
for (int i=0; i< length; i++)
{
byte[] bytes = new byte[1];
rng.GetBytes(bytes);
Random rnd = new Random(bytes[0]);
chars[i] = validChars[rnd.Next(0,61)];
}
return (new string(chars));
}

ASP.NET 2.0 tutorial

Hi All,

Below is the link for asp.net 2.0 tutorial.Its really nice have a look at it

http://msconline.maconstate.edu/tutorials/ASPNET20/default.htm
Happy coding

Review Books

  • ASP.NET WebService
  • Learn VisualStudio.net
  • Basic .NET Framework
  • Basic C#
  • .NET Interview Questions
  • C# 2005 Programming