.net code snippets
Thursday, February 7, 2008
c#: to send the email in html format
using System;
using System.Net.Mail;
using System.Net.Mime;
using System.Drawing;
namespace RnDConsoleCSharp
{
class Program
{
static void Main(string[] args)
{
SendMail();
Console.Read();
}
//program to send mail
public static void SendMail()
{
/******* IMAGE FOR EMAIL *********/
Image EmailLogo = RnDConsoleCSharp.Resources.mylogo;
byte[] commentImg;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
EmailLogo.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg );
commentImg = stream.ToArray();
}
/**********************************/
try
{
MailAddress from = new MailAddress("rupeshn@mindfiresolutions.com");
MailAddress to = new MailAddress("logintoabhi@hotmail.com");
MailMessage message = new MailMessage(from, to);
message.IsBodyHtml =true;
message.Subject ="TEST with image";
string bodyText = "
";
message.Body = bodyText;
SmtpClient client = new SmtpClient("NETSERVER");
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("E-Mail Failed\n\n" + ex, "Email");
}
}
}
}
using System.Net.Mail;
using System.Net.Mime;
using System.Drawing;
namespace RnDConsoleCSharp
{
class Program
{
static void Main(string[] args)
{
SendMail();
Console.Read();
}
//program to send mail
public static void SendMail()
{
/******* IMAGE FOR EMAIL *********/
Image EmailLogo = RnDConsoleCSharp.Resources.mylogo;
byte[] commentImg;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
EmailLogo.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg );
commentImg = stream.ToArray();
}
/**********************************/
try
{
MailAddress from = new MailAddress("rupeshn@mindfiresolutions.com");
MailAddress to = new MailAddress("logintoabhi@hotmail.com");
MailMessage message = new MailMessage(from, to);
message.IsBodyHtml =true;
message.Subject ="TEST with image";
string bodyText = "
Staff Name: | \" + staffName + \" |
Staff Query: | \" + queryText + \" |
message.Body = bodyText;
SmtpClient client = new SmtpClient("NETSERVER");
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("E-Mail Failed\n\n" + ex, "Email");
}
}
}
}
Wednesday, February 6, 2008
c # code that shows all drives including network drives.
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
namespace RnDConsoleCSharp
{
class Program
{
static void Main(string[] args)
{
string driveLabel = null ;
ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From Win32_LogicalDisk ");
ManagementObjectCollection queryCollection = query.Get();
foreach (ManagementObject mo in queryCollection)
{
driveLabel = Convert.ToString(mo["VolumeName"] );
if (driveLabel.Length == 0)
{
driveLabel = Convert.ToString(mo["Description"]);
}
driveLabel += " (" + Convert.ToString(mo["Name"]) + ")";
Console.WriteLine(driveLabel);
}
Console.Read();
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Management;
namespace RnDConsoleCSharp
{
class Program
{
static void Main(string[] args)
{
string driveLabel = null ;
ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From Win32_LogicalDisk ");
ManagementObjectCollection queryCollection = query.Get();
foreach (ManagementObject mo in queryCollection)
{
driveLabel = Convert.ToString(mo["VolumeName"] );
if (driveLabel.Length == 0)
{
driveLabel = Convert.ToString(mo["Description"]);
}
driveLabel += " (" + Convert.ToString(mo["Name"]) + ")";
Console.WriteLine(driveLabel);
}
Console.Read();
}
}
}
Subscribe to:
Posts (Atom)
Blog Archive
About Me
- Abhishek Kumar Singh
- He is working in an indian firm as a s/w engineer.During his work in the company he got many opportunities to deal with. He has experience on high-end techonologies like ASP, VB 6.0, MS.Net 2005, WMS, Python, Ajax, Ruby on Rails etc. He likes to work on client-server systems, remoting, web services, windows services etc. He loves to create utilities that makes his work easier and faster.