Sending email thru C#, .NET 2.0 , with attachment,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
namespace MailConnect
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Sendbutton_Click(object sender, EventArgs e)
{
MailMessage aMessage = new MailMessage("matespoint@gmail.com", "xyz@yahoo.com");
aMessage.Subject = "This is test message";
aMessage.Body = "Body text message";
Attachment aT = new Attachment("C:\files.doc");
aMessage.Attachments.Add(aT);
aT = new Attachment("C:\files.pdf");
aMessage.Attachments.Add(aT);
SmtpClient aClient = new SmtpClient(servername, 25);
aClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
aClient.Send(aMessage);
MessageLabel.Text = "Mail has been sent successfully";
}
}
}
Mar 29, 2007
Mar 22, 2007
Concatenate strings from a column into a single row?
CREATE DATABASE Test1
Go
Use Test1
set nocount on
CREATE TABLE dbo.Test2
(
Col1 int identity,
Col2 varchar (5) default('aaaaa')
)
declare @loop
int set @loop = 1
while @loop <= 100
begin
insert into Test2 default values
set @loop = @loop + 1
end
Now you had create a Database Test1 and a Table Test2 with 100 records
Now concatenate this to a single string
DECLARE @ConcatString varchar(8000)
SELECT @ConcatString = COALESCE(@ConcatString + ',','' ) + CAST(Col1 as varchar(12))
FROM Test2
SELECT @ConcatString
You can find the same result by using ISNULL
DECLARE @ConcatString varchar(8000)
SELECT @ConcatString = ISNULL(@ConcatString + ',','' ) + CAST(Col1 as varchar(12))FROM Test2
SELECT @ConcatString
Enjoy .. .. better performance using this instead of using CURSOR.
Go
Use Test1
set nocount on
CREATE TABLE dbo.Test2
(
Col1 int identity,
Col2 varchar (5) default('aaaaa')
)
declare @loop
int set @loop = 1
while @loop <= 100
begin
insert into Test2 default values
set @loop = @loop + 1
end
Now you had create a Database Test1 and a Table Test2 with 100 records
Now concatenate this to a single string
DECLARE @ConcatString varchar(8000)
SELECT @ConcatString = COALESCE(@ConcatString + ',','' ) + CAST(Col1 as varchar(12))
FROM Test2
SELECT @ConcatString
You can find the same result by using ISNULL
DECLARE @ConcatString varchar(8000)
SELECT @ConcatString = ISNULL(@ConcatString + ',','' ) + CAST(Col1 as varchar(12))FROM Test2
SELECT @ConcatString
Enjoy .. .. better performance using this instead of using CURSOR.
Mar 16, 2007
Few Definitions
- School: A place where Papa pays and Son plays.
- Life Insurance: A contract that keeps you poor all your life so that you can die Rich.
- Nurse: A person who wakes u up to give you sleeping pills.
- Marriage: It's an agreement in which a man loses his bachelor degree and a woman gains her masters.
- Divorce: Future tense of Marriage.
- Tears : The hydraulic force by which masculine willpower is defeated byfeminine waterpower.
- Lecture: An art of transferring information from the notes of the Lecturer to the notes of the students without passing through "the minds of either"
- Conference: The confusion of one man multiplied by the number present.
- Compromise : The art of dividing a cake in such a way that everybody believes he got the biggest piece.
- Dictionary : A place where success comes before work.
- Conference Room : A place where everybody talks, nobody listens and everybody disagrees later on.
- Father : A banker provided by nature.
- Criminal: A guy no different from the rest....except that he got caught.
- Boss : Someone who is early when you are late and late when you are early.
- Politician : One who shakes your hand before elections and your Confidence after.
- Doctor : A person who kills your ills by pills, and kills you by bills.
- Classic : Books, which people praise, but do not read.
- Smile : A curve that can set a lot of things straight.
- Office : A place where you can relax after your strenuous home life.
- Yawn: The only time some married men ever get to open their mouth.
- Etc .: A sign to make others believe that you know more than you actually do.
- Committee : Individuals who can do nothing individually and sit to decide that nothing can be done together.
- Experience: The name men give to their mistakes.
- Atom Bomb : An invention to end all inventions.
- Philosopher : A fool who torments himself during life, to be spoken of whendead
Hope you enjoy ... Have fun ...
Write your definitions if you want to share one
Application Domain
An Application Domain is a light weight process and provides a logical and physical isolation from another .NET application.
- This ensures that the Applications can work independent and isolated of each other. An Application Domain is created by the Common Language Runtime (CLR) and it ensures that if one Application Domain crashes or goes down, it does not in any way effect the functioning of another Application Domain.
- Multiple .NET applications can be executed in one single process by loading these applications in separate Application Domains.
- Several threads can be executing in a single application domain at any given time and a particular thread is not confined to a single application domain. In other words, threads are free to cross application domain boundaries and a new thread is not created for each application domain.
- The following are the benefits of Application Domains.
Isolation of code, data and configuration information of one application from another
A failure in one application will not affect the other
Abstract Class Vs Interface
Abstract Class Vs Interface
There are a lot of discussion on the internet about the Interface vs Abstract class. and also , as BASE class whether we should use interface, abstract class or normal class.
Abstract Class vs Interface
We can not make instance of Abstract Class as well as Interface.
Here are few differences in Abstract class and Interface as per the definition.
Abstract class can contain abstract methods, abstract property as well as other members (just like normal class).
Interface can only contain abstract methods, properties but we don’t need to put abstract and public keyword. All the methods and properties defined in Interface are
by default public and abstract.
using System;
namespace ConsoleApplication2
{
////// Summary description for Class2. ///
public abstract class A
{
int someInt;
string someString;
public A()
{ // // TODO: Add constructor logic here // }
public abstract void F();
}
public class B : A
{
public override void F()
{ Console.WriteLine("F in B"); }
}
interface IA
{
//int someInt; give error we cant have fields in interface
//string someString;
string P{get;set;}
void F();
}
public class C : IA
{
public C() { }
public string P
{
get {return _p;}
set {_p = value;}
}
public void F()
{
Console.WriteLine("Abstract F()");
}
private string _p; }
}
we can make the call like this..
B b = new B();
b.F();
A a = b;
a.F();
//A a = new A(); will give error as we cant instantiate
C c = new C();
c.F();
c.P="Test String";
Console.WriteLine(c.P.ToString());
IA d = c;
d.F();
Console.WriteLine(c.P.ToString());
Console.Read();
Output :
F in B
F in B
Abstract F()
Test String
Abstract F()
Test String
We can see abstract class contains private members also we can put some methods with implementation also. But in case of interface only methods and properties
allowed.
We use abstract class and Interface for the base class in our application.Now most important question: What should use : Interface force everybody to implement all things in that. So use it when u wanna force all the methods, properties, etc to implement.Abstract Class - limited you to create an instance of this class, and if you derived from this class you have to implement all abstract members to create an instance of this derived class. Also Abstract class should used when you have some functions which you must override and some which you can leave in this scenerio use abstract classes,
There are a lot of discussion on the internet about the Interface vs Abstract class. and also , as BASE class whether we should use interface, abstract class or normal class.
Abstract Class vs Interface
We can not make instance of Abstract Class as well as Interface.
Here are few differences in Abstract class and Interface as per the definition.
Abstract class can contain abstract methods, abstract property as well as other members (just like normal class).
Interface can only contain abstract methods, properties but we don’t need to put abstract and public keyword. All the methods and properties defined in Interface are
by default public and abstract.
using System;
namespace ConsoleApplication2
{
///
public abstract class A
{
int someInt;
string someString;
public A()
{ // // TODO: Add constructor logic here // }
public abstract void F();
}
public class B : A
{
public override void F()
{ Console.WriteLine("F in B"); }
}
interface IA
{
//int someInt; give error we cant have fields in interface
//string someString;
string P{get;set;}
void F();
}
public class C : IA
{
public C() { }
public string P
{
get {return _p;}
set {_p = value;}
}
public void F()
{
Console.WriteLine("Abstract F()");
}
private string _p; }
}
we can make the call like this..
B b = new B();
b.F();
A a = b;
a.F();
//A a = new A(); will give error as we cant instantiate
C c = new C();
c.F();
c.P="Test String";
Console.WriteLine(c.P.ToString());
IA d = c;
d.F();
Console.WriteLine(c.P.ToString());
Console.Read();
Output :
F in B
F in B
Abstract F()
Test String
Abstract F()
Test String
We can see abstract class contains private members also we can put some methods with implementation also. But in case of interface only methods and properties
allowed.
We use abstract class and Interface for the base class in our application.Now most important question: What should use : Interface force everybody to implement all things in that. So use it when u wanna force all the methods, properties, etc to implement.Abstract Class - limited you to create an instance of this class, and if you derived from this class you have to implement all abstract members to create an instance of this derived class. Also Abstract class should used when you have some functions which you must override and some which you can leave in this scenerio use abstract classes,
Mar 1, 2007
Difference between out and ref - out vs ref
In the case of Ref - assignment is needed before passing to the function
In the case of Out - no assignment is required, but you must assign a value in which function this is passed,
For Ex:
using System;
namespace ConsoleApplication2
{
///
/// Summary description for Class1.
///
class Class1 {
public static void Foo_Ref(ref int i)
{
//i = 2; //Dont gives a error
}
public static void Foo_Out(out int i)
{
//i=3; //it gives an error i must be assigned before leaving this function.
}
public static void Test()
{
int a ; Foo_Ref(ref a); //it gives an error coz a is not assigned a value
Console.WriteLine("Ref Case {0}",a);
Foo_Out(out a);
Console.WriteLine("Out Case {0}",a);
}
[STAThread] static void Main(string[] args)
{ //return MessageBoxA(0,"Hello Irfan","Caption",0);
Test();
Console.Read();
}
}
}
In the case of Out - no assignment is required, but you must assign a value in which function this is passed,
For Ex:
using System;
namespace ConsoleApplication2
{
///
/// Summary description for Class1.
///
class Class1 {
public static void Foo_Ref(ref int i)
{
//i = 2; //Dont gives a error
}
public static void Foo_Out(out int i)
{
//i=3; //it gives an error i must be assigned before leaving this function.
}
public static void Test()
{
int a ; Foo_Ref(ref a); //it gives an error coz a is not assigned a value
Console.WriteLine("Ref Case {0}",a);
Foo_Out(out a);
Console.WriteLine("Out Case {0}",a);
}
[STAThread] static void Main(string[] args)
{ //return MessageBoxA(0,"Hello Irfan","Caption",0);
Test();
Console.Read();
}
}
}
Feb 28, 2007
This is my first Post on my Blog
Hi,
I, Mohammad Irfan, welcomes you at my blog, and also thanks you for your time. This is my first post and hence I just want to introduce my self.
Well, I am Mohammad Irfan, holding a Master Degree in Computer Science and a Bachelor Degree in Physics (Hons.) from AMU in 2004 and 2001 respectively. I did my schooling from various parts of UP, like Azamgarh, Kushi Nagar, Deoria, Basti and Siddhartha Nagar, basically all these Districts are in East UP.
My interests include playing cricket, watching movies, surfing net and explore to new technologies{actually trying to do it}.
This is my first step towards being connected to the word.
In my blog, I just want to put everything which I find interesting irrespective of which categories it shoud be.
Thanking you.
Irfan
{matespoint@gmail.com}
I, Mohammad Irfan, welcomes you at my blog, and also thanks you for your time. This is my first post and hence I just want to introduce my self.
Well, I am Mohammad Irfan, holding a Master Degree in Computer Science and a Bachelor Degree in Physics (Hons.) from AMU in 2004 and 2001 respectively. I did my schooling from various parts of UP, like Azamgarh, Kushi Nagar, Deoria, Basti and Siddhartha Nagar, basically all these Districts are in East UP.
My interests include playing cricket, watching movies, surfing net and explore to new technologies{actually trying to do it}.
This is my first step towards being connected to the word.
In my blog, I just want to put everything which I find interesting irrespective of which categories it shoud be.
Thanking you.
Irfan
{matespoint@gmail.com}
Subscribe to:
Posts (Atom)
-
Clustered Index | Non Clustered Index Indexing is used to get fast retrival of data. The indexing which is done on physical storage is known...
-
All about Haj, please visit http://www.hajcommittee.com This year UP haj pilgrims will be decided on lottery draw due to more responces of l...
-
To get all the triggers list and their scripts run the script below. View the result in file view mode. SELECT [text] FROM sysobjects o ...