Tuesday, December 02, 2008

email Query result



MailMessage mail = new MailMessage();
mail.To = HLBLUserEmail.Text;
mail.From = "'Sender<sendere@domain.com>";
//mail.Headers.Add("Reply-To", "sender@domain.com");
mail.Subject = "Subject";
mail.BodyFormat = MailFormat.Html;

mail.Body = "<div style='position:relative; left: 50px;'><p>";
mail.Body += "" + DateTime.Now + "<br />";
mail.Body += "<br/>Dear, " + userName + "<br />";
mail.Body += "<br />Your order has been submitted.<br />";
mail.Body += "Order Number is : " + orderID + ";";
mail.Body += "<br />Following is the list of ordered items:<br /></p>";

String strConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(strConnectionString);
string ItemNo, Description, Price, qty;
mail.Body += "<table border='1' style='font-size: 8pt;'>";

foreach (GridViewRow row in GridView1.Rows)

{
ItemNo = (row.FindControl("ItemNo") as Label).Text;
Description = (row.FindControl("Description") as Label).Text;
Price = (row.FindControl("Price") as Label).Text;
qty = (row.FindControl("SelectedQty") as Label).Text;

mail.Body += "<tr>";
mail.Body += "<td>" + ItemNo + "</td><td>" + Description + "</td><td>" + Price + "</td><td>" + qty + "</td><td>" + Convert.ToInt32(Price) * Convert.ToInt32(qty) + "</td>";
mail.Body += "</tr>";
}

mail.Body += "</table></div><br /><br /><br />";

SmtpMail.SmtpServer = "smtp.domain.com";
SmtpMail.Send(mail);

Search for Active Directory information

snippet for searching active directory for name, email, memberof(useless) and datecreated.

// String UserID = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();

String UserID = Environment.UserName;

string account = UserID;
Label3.Text = "Search for this accont: " + account;

DirectoryEntry entry = new DirectoryEntry("LDAP://DOMAIN", "username", "password");
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + account + ")";
search.PropertiesToLoad.Add("displayName");
search.PropertiesToLoad.Add("mail");
search.PropertiesToLoad.Add("memberof");
search.PropertiesToLoad.Add("whencreated");

SearchResult result = search.FindOne();

if (result != null)
{
Label4.Text = "displayName: " + result.Properties["displayname"][0].ToString();
Label5.Text = "mail: " + result.Properties["mail"][0].ToString();
Label6.Text = "memberof: " + result.Properties["memberof"][0].ToString();
Label7.Text = "whencreated: " + result.Properties["whencreated"][0].ToString();

}

else
{
Label4.Text = "Unknown User";
}

Monday, December 01, 2008

Agile Programming

Just something i found. indeed, i am glad it has a name. i should put it on my resume.