November 9, 2005
MSN Sandbox !!!
November 7, 2005
System.Net.Mail
public void SendEmail()
{
//.Net 1.0 System.Web.Mail -- Is now Depre
/*
//We can use the constructor as well; e.g.
/*MailMessage mail = new MailMessage("ludmal@test.com", "ludmal@tst.lk", "Test", "test");*/
MailMessage mail = new MailMessage();
mail.To = "ludmal@e-solutions.lk";
mail.From = "ludmal@test.com";
mail.Body = "Body Testing";
SmtpMail.SmtpServer = "mail";
SmtpMail.Send(mail);
*/
//.Net 2.0 System.Net.Mail
MailMessage mail = new MailMessage("ludmal@test.com", "ludmal@tst.lk", "Test", "test");
/*MailAddressCollection col = new MailAddressCollection();
MailAddress sendAdd = new MailAddress("ludmal@e-solutions.lk");
*/
System.Net.Mail.SmtpClient client = new SmtpClient("mysmtp");
client.Send(mail);
}
November 4, 2005
Google's new RSS Reader
November 3, 2005
Socket Programming using .Net 2.0 System.Net.Socket
Server Code:
class MyServer
{
//Listing to the client connections.
public void Listen()
{
byte[] ipArray = new byte[4];
ipArray[0] = 127;
ipArray[1] = 0;
ipArray[2] = 0;
ipArray[3] = 1;
IPAddress add = new IPAddress(ipArray);
//This is obselete in .Net 2.0
//TcpListener tcpListener = new TcpListener(10);
TcpListener tcpListener = new TcpListener(add, 10);
tcpListener.Start();
Socket socketForClient = tcpListener.AcceptSocket();
if (socketForClient.Connected)
{
Util.Out("client connected..");
NetworkStream netStream = new NetworkStream(socketForClient);
StreamWriter writer = new StreamWriter(netStream);
StreamReader reader = new StreamReader(netStream);
string str = "Message from Server : " + DateTime.Now.ToLongDateString();
writer.WriteLine(str);
Util.Out("What meessage do you want to send to client?");
writer.WriteLine(Console.ReadLine());
writer.Flush();
str = reader.ReadLine();
Util.Out(str);
reader.Close();
writer.Close();
netStream.Close();
}
socketForClient.Close();
Util.Out("Exiting...");
}
}
Client Code :
public class MyClient
{
//Connects to the server
public void Connect()
{
TcpClient socketForServer = null;
try
{
socketForServer = new TcpClient("localhost", 10);
Util.Out("Connected to the Server");
}
catch
{
Util.Out("Failed to connecto localhost");
Util.Out("Exiting..");
return;
}
NetworkStream netstream = socketForServer.GetStream();
StreamReader reader = new StreamReader(netstream);
StreamWriter writer = new StreamWriter(netstream);
try
{
string output1, output2;
output1 = reader.ReadLine();
output2 = reader.ReadLine();
Util.Out(output1);
Util.Out(output2);
writer.Flush();
reader.Close();
}
catch
{
Util.Out("Exception Occured! Exiting...");
}
netstream.Close();
}
}
This is small helper class…
public class Util
{
public static void Out(string s)
{
Console.WriteLine(s);
}
}
This is a simple console application. You can create two console application one for the server & one for the client. Run the server first then client app. If you want you can create nice windows applications using this two simple classes to communicate over network.
November 2, 2005
C# 2.0 : String comparison
Class diagrams in VS 2005
.
October 31, 2005
GMail Drive
You can download it from http://www.viksoe.dk/code/gmail.htm
October 28, 2005
Creating a Screen Saver with Visual Studio 2005
With VS 2005 it’s possible. You can create your own screen saver without any coding. I will explain the basic steps to create your screen saver in minutes. Of course you will get the complete help info from the VS itself. So lets start your RSS feed screen saver.
Open the VS 2005, File > New > Project
New project dialog box will appear. Select the Starter Kits > Screen Saver Starter Kit
Click ok. You can go ahead and change the code for your requirements or else you can keep the default. Build the project & go to the project BIN folder. You will find ssNews.scr file in it. Copy & Paste the file into the %SystemRoot%\system32\ folder.(e.g. WINNT\system32\) Your done!. Great VS has created screen saver for you in just seconds. Select the screen saver (News) from the Screen saver tab from the Display settings & change the RSS feed from the Screen Saver Settings. You can customize the background picture / RSS feed / shortcut keys... whatever since we got the source code. So try it & have fun.
October 19, 2005
I'm @ TechEd

(Im at teched with my very good old friend Sumudu)
October 11, 2005
TechEd ! im sponsered :-)
October 10, 2005
Brute Force Attacks.
Brute Force attacks are closely related to dictionary attacks. Brute force attack generates random user ids and passwords instead of reading them from a dictionary file.
Now suppose a user has a six-character password that consists of upper-and lowercase letters, digits and 32 punctuation characters. There are 689,869,781,056 password combinations. A brute force attack would require 1,093 years on average to find the correct password. This comparison doesn’t mean brute force attacks aren’t a threat, but it does make it clear how much more dangerous dictionary attacks are. I will post a code sample about how to create a dictionary attack & how we can prevent from it. So stay tuned.
October 3, 2005
Visual Studio: What’s in a code Name?
September 28, 2005
Best approach for a 3 tier application ?
September 27, 2005
Discussion About Microsoft Patterns & Practices
September 26, 2005
Share your videos with Google
September 23, 2005
Custom Objects with Web Services
So today im going to explain how to return a custom object through web service. I will explain the scenario from a simple diagram.( banks needs a valid telephone number to issue a credit card its a fact)
In this scenario Telephone Company is offering a web service to its partners to get the customer just by supplying customers telephone number.
Customer class:
public class Customer
{
public Customer()
{
//
// TODO: Add constructor logic here
//
}
string _name;
string _age;
string _company;
public string Name
{
get{return _name;}
set{_name = value;}
}
public string Age
{
get{return _age;}
set{_age = value;}
}
public string Company
{
get{return _company;}
set{_company = value;}
}
}
GetCustomer web service method which returns the customer object
[WebMethod]
public Customer GetCustomer()
{
//can be perform any database functions
Customer customer = new Customer();
customer.Name = "Ludmal de silva";
customer.Age = "25";
customer.Company = "E-Solutions";
return customer;
}
Now we can use this web service by simply adding a web reference to our project.(you guys should know how to add a web reference its really simple).
Finally you can get the customer object which returns from the web service. Code below.
//Customer object
CustomerService.Customer customer = new CustomerService.Customer();
//CustomerService object
CustomerService.Service1 myCustomerService = new CustomerService.Service1();
///Get the customer from the WebService
customer = myCustomerService.GetCustomer();
//Assigning the values to the UI
this.Label1.Text = customer.Name;
this.Label2.Text = customer.Company ;
this.Label3.Text = customer.Age ;
What I was trying to do is to give a basic idea about web services & to use the custom object with web services. I highly appreciate comments. (my writing skills might be poor...) But all the questions /comments are welcome.
September 22, 2005
Custom DataGrid with client side behavior
September 21, 2005
Power of CSS
http://www.csszengarden.com/
September 20, 2005
Using Web User Control
Web user control is playing a major role in asp.net development. Its hardly possible to develop a application without web user controls. But most of developers are not using it properly. In this article I just thought to share some powerful features of web user control. Microsoft .Net framework is fully object oriented implementation. So we have to take advantage of it. We can learn lots of things by looking at the Microsoft class library. So lets start simple sample to show proper use of Web user control.
Scenario: We have to create 3(might be more) Registration forms in different formats. But the Mailing Address section is always stays the same. We need to accomplish this in minimum effort with a Web User Control in OOP manner.
Solutions: So lets start creating simple Web User Control name AddressUI;

In code behind of the AddressUI insert the below code
//AddressUI Properties
public string Street1
{
get {return this.txtStreet1.Text ;}
set {this.txtStreet1.Text = value;}
}
public string Street2
{
get {return this.txtStreet2.Text ;}
set {this.txtStreet2.Text = value;}
}
public string City
{
get {return this.txtCity.Text ;}
set {this.txtCity.Text = value;}
}
public string Country
{
get {return this.txtCountry.Text ;}
set {this.txtCountry.Text = value;}
}
public bool ContactMe
{
get {return this.chkContactMe.Checked ;}
set {this.chkContactMe.Checked = value;}
}
Now you can use this AddressUI control in any page u wanted. Giving u easily maintainable UI. Let me show you how u can use this control in your ASP.net pages.
Drag & drop the control into the page. You can access the controls property. Check the below code.
Declare the AddressUI control
protected AddressUI AddressUI1;
then access its properties, Add this code to a button click event.
Response.Write(AddressUI1.City + AddressUI1.Country );
your done. You can assign its properties to another objetecs properties.. no hassle doing Page.FindControl & no casting at all.

