Thursday, December 29, 2005

Wednesday, December 28, 2005

Regular Expression: Multiple replacement in one go

One of the overloaded form of Regex.Replace function takes MatchEvaluator delegate as a parameter. We can use this form to achieve multiple (conditional) replacement in one go.

For Example:
// Replace Textboxes
string regex = "\\
";
System.Text.RegularExpressions.RegexOptions options = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace
| System.Text.RegularExpressions.RegexOptions.Multiline)
| System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(regex, options);
pageContent = reg.Replace(pageContent,new MatchEvaluator(RemoveFormElement));

protected string RemoveFormElement(Match m)
{
if(m.Value.IndexOf("RemoveFeedback") != -1)
{
string feedback = Regex.Replace(txtFeedback.Text,"\\n","
"
);
return ""+feedback+"";
}
else if (m.Value.IndexOf("RemoveContextHeader") != -1)
{
return ""+ contextHeader +"";
}
else
{
return m.Value;
}

}

Monday, December 05, 2005

Useful Window Tricks

Check out these 10 useful window tricks.

http://www.practicalpc.co.uk/computing/windows/top10tricks1.htm

Binding of DictionaryBase object with Datagrid instead of Collection Object

Following excerpts demonstrate how we can bind dictionary object with datagrid.

<asp:Label id="Label1" runat="server" Width="64px">
<%#((DictionaryEntry)Container.DataItem).Key %>
<br>
<%# ((TestApplication.ContactsInfo)((DictionaryEntry)Container.DataItem).Value).age%>

Prometric Test Centers in India

To find out prometric centers of your preferred location, visit following link:
http://www.register.prometric.com/Centers.asp

Following are some of the centers in New Delhi:

SQL STAR INTERNATIONAL LTD
NEW DELHI, Delhi 110003
Phone: 24601539 Site Code: IIU1 3RD FLOOR,
ANDHRA ASSOCIATION BULDING
24 & 25,
LODHI ROAD

C-NET EDUCATION
NOIDA, Uttar Pradesh
Phone: 5320373,2440594 Site Code: IIF94 D-3
SECTOR -10

IACL (Institute of Advance computer Learning)
NEW DELHI, Delhi 110049
Phone: 55484641 Site Code: IIG66 IACL
H-28,2ND-FLOOR
SOUTH EXTENSION PART-I

CMC LIMITED
NEW DELHI, Delhi 110058
Phone: 25572355 Site Code: IIG29 C-58,9TH FLOOR, SHAHPURI TIRATH SINGH TOWER
BEHIND JANAK CINEMA, JANAKPURI

VIVEKANAND INSTITUTE OF COMPUTER EDUCATION(VICE)-MOBILE SITE
DELHI, Delhi 110009
Phone: 55278088 Site Code: IIM83 VIVEKANAND INST. OF COMPUTER EDUCATION-MOBILE
2647
HUDSON LINE
NEAR NORTH CAMPUS
PATEL CHEST

Wednesday, November 30, 2005

PHP script Example

Below is basic PHP script which demonstrates MySQL and Active Directory communication :

";
mysql_close($dblink);


/* Going a step forward now we will connect to ldap server */
$ldapserver = "xxxx";

$user = "cn=Ashish Srivastava,cn=Users,dc=mydomamin,dc=com";
$passwd = "ashish";
$base = "cn=Users,dc=mydomamin,dc=com";


// Connect to ldap server
$dsCon = ldap_connect($ldapserver);


// Make sure we connected
if (!($dsCon))
{

print("Sorry, cannot contact LDAP server");
exit(2);

}


// Set Active Directory Specific Options
ldap_set_option($dsCon,LDAP_OPT_REFERRALS, 0);


// Bind LDAP
$bindresult = ldap_bind($dsCon,$user,$passwd);

if(!$bindresult){
$errno = ldap_errno($dsCon);
$error = ldap_error($dsCon);

print "LDAP Error ($errno): $error";
exit(3);
}


// Now Perform Search
$attributes = array("cn"); // attributes which you want

$search_filter = "(&(objectclass=user)(objectcategory=user)(sAMAccountName=ashish.srivastava))";
$search_result=ldap_search($dsCon, $base, $search_filter, $attributes);
if(!$search_result){
$errno = ldap_errno($dsCon);
$error = ldap_error($dsCon);

print "LDAP Error ($errno): $error";
exit(4);
}


// Getting Entries
$entry = ldap_get_entries($dsCon,$search_result);

if(!$entry){
$errno = ldap_errno($dsCon);
$error = ldap_error($dsCon);

print "LDAP Error ($errno): $error";
exit(4);
}


$cn = $entry[0]["cn"][0];
//var_dump($entry);
print "Common Name: $cn
";
ldap_close($dsCon);
?>

Tuesday, November 29, 2005

Codus - Code generation tool for .NET

Codus, a code generation tool by Adapdev Technologies provide excellent integration with variety of databases like SQL Server, Oracle and MySQL.

Cool Tools for .NET developers

Check out these cool tools. They are really handy.
Cool Tools

C# Interface Explained

I have never got so good explaination even in the good C# books. Interview in this article beautifully explains C# Interface.
http://dotnet.org.za/brianwilson/archive/2005/04/19/18306.aspx

Custom HTTP Modules

Custom HTTP Modules

HTTP Modules provides an opportunity to examine each incoming and outgoing request before request processing.
A typical use of HTTP module is URL rewriting on the basis of content of URL string. For example if i want to convert URL like "mywebproject/ashish/default.aspx" into "mywebproject/default.aspx?user=ashish" or vice-versa.

Creating custom HTTP Modules:

  • Make a class for implementing your custom module and implement IHttpModule Interface.
  • Add event handlers for BeginRequest and EndRequest events
  • Register your custom HTTP Module using web.config
Make a class and adding Event Handlers:
 public class UrlMapperModule : IHttpModule
{
private EventHandler onBeginRequest;

public UrlMapperModule()
{
onBeginRequest = new EventHandler(this.HandleBeginRequest);
}

void IHttpModule.Dispose()
{
}

void IHttpModule.Init(HttpApplication context)
{
context.BeginRequest += onBeginRequest;
}


private void HandleBeginRequest( object sender, EventArgs evargs )
{
// Now check every request
string requestUrl = app.Context.Request.Url.PathAndQuery;
}
}
Registering Custom HTTP Module in web.config: