Friday, July 27, 2007

Select box manipulation with jQuery - update to removeOption

The previous update to this collection of plugins introduced a cache when adding options (i.e. made it much faster if adding a lot of options). However, it was not cleared when remove options (causing possible conflicts). This is now done and an extra parameter has been added to removeOption (of boolean type), that when set to true, will only remove options if it matches any option(s) defined by the first parameter. More details and download from the Select Box Manipulation project page at the jQuery site. A demo is also available.

Thursday, July 12, 2007

FileHelpers - a library for worked with CSV files (.NET)

Best described in the words on the FileHelpers website:

The FileHelpers are a free and easy to use .NET library to import/export data from fixed length or delimited records in files, strings or streams.

It is a library that can be used to work with flat text files (e.g. Comma Separated Value (CSV) or Tab Separated Values (TSV) etc). Available for commercial and non-commercial use (under the LGPL). They also have a blog.

There is also a CSV parser on CodeProject if you can't use a library licensed under the LGPL: A Fast CSV Reader. Not as powerful as FileHelpers but still good nonetheless.

Wednesday, July 11, 2007

Text Clips for Programmers Notepad 2 (jQuery)

I have not updated my jQuery Text Clips for Programmer's Notepad 2 for a while (since 1.0.2) so have added them for jQuery 1.1.2 @ Text Clips for Programmer's Notepad 2 (generated using the jQuery Text Clip Generator).

Thursday, July 05, 2007

Sending emails with C#

I'm sure many may already know how to do this, but for those that don't, sending an email using .NET is very easy and can be used in ASP.NET as well as Windows Forms or Console applications (assuming you have CDOSYS installed). This example also shows how to send an email to multiple recipients (requires you to import the namespace System.Collections).

.NET 1.0 / 1.1 (import the namespace System.Web.Mail)
MailMessage m;
SmtpMail.SmtpServer = "smtpservername";
ArrayList recipients = new ArrayList();
recipients.Add("fred@bloggs.com");
recipients.Add("jane@doe.com");
for (int i = 0;i < recipients.Count;i++)
{
 m = new MailMessage();
 m.To = recipients[i].ToString();
 m.From = "me@mysite.com";
 m.BodyFormat = MailFormat.Html;
 m.Subject = "Subject of the email";
 m.Body = String.Format(
  "<p style='font: 12px Arial'>Sending email to {0}</p>",
  recipients[i]
 );
 SmtpMail.Send(m);
}
.NET 2.0+ (import the namespace System.Net.Mail)
MailMessage m;
SmtpClient smtp = new SmtpClient("smtpservername");
ArrayList recipients = new ArrayList();
recipients.Add("fred@bloggs.com");
recipients.Add("jane@doe.com");
for (int i = 0;i < recipients.Count;i++)
{
 m = new MailMessage();
 m.To = recipients[i].ToString();
 m.From = "me@mysite.com";
 m.IsBodyHtml = true;
 m.Subject = "Subject of the email";
 m.Body = String.Format(
  "<p style='font: 12px Arial'>Sending email to {0}</p>",
  recipients[i]
 );
 smtp.Send(m);
}