DevelopmentNow Blog
 Wednesday, October 26, 2005

Yes, free. Microsoft is doing a 200-city US tour over the next two months to promote Visual Studio 2005, SQL Server 2005, and BizTalk Server 2006. Not only is it an all-day event with speakers, classes, Q&A sessions, and more, but they're giving away a free copy of VS 2005 & SQL Server 2005 to all attendees (while supplies last). Best of all, it costs nothing to register.

So check out the Visual Studio 2005 Launch Tour site and register. And get free stuff. And then start developing -- believe me, the new tools are sweet.

October 26, 2005    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Wednesday, October 19, 2005

It's often handy to have your web site or application send emails. "Thanks for registering." "Thanks for your order." "Hey tech support, the web site is down."

.NET 2.0 provides a few handy classes for outbound emails. Below is some code you can use in your ASP.NET application to send an email. Notice there is some authentication code you can use if your SMTP server requires a username and password in order to send emails. If you aren't sure, try sending an email without a username or password. If you get an SmtpException with a 550 or 553 Relay denied error (SmtpException.StatusCode == SmtpStatusCode.ClientNotPermitted), then you'll need to authenticate. :)

// create the message object
System.Net.Mail.MailMessage myMessage = new System.Net.Mail.MailMessage();

myMessage.To[0] = "some.guy@hotmail.com";
myMessage.From = "some.girl@hotmail.com";
myMessage.Subject = "this is a test message";
myMessage.Body = "hello there!\ntest message!";

// create the SmtpClient object. Specify the SMTP server in the Host property
System.Net.Mail.SmtpClient mySMTPClient = new System.Net.Mail.SmtpClient();
mySMTPClient.Host = "smtpserver.emailfarm.com";

if (SMTP_SERVER_REQUIRES_AUTHENTICATION)
{
	// create the NetworkCredential object with the username & password 
	// to authenticate against the SMTP server
	System.Net.NetworkCredential myCredentials = 
		new System.Net.NetworkCredential("username", "password");
	mySMTPClient.UseDefaultCredentials = false;
	mySMTPClient.Credentials = myCredentials;
}

// send the message
try
{
	mySMTPClient.Send(myMessage);
}
catch (SmtpException e)
{
	Response.Write(e.StatusCode);
}

If you feel the need to email a file to someone, use code like the below

// Attach a file to the email message. 
// The second parameter is the content type (text, binary file, etc.)
System.Net.Mail.Attachment myAttachment = new Attachment(strFilename, MediaTypeNames.Text.Plain);
myMessage.Attachments.Add(myAttachment);

Lastly, you can send an email asynchronously via the SmtpClient.SendAsync(MailMessage, CallbackToken) method. You can attach an event handler to the SmtpClient.SendCompleted event to receive notification when your email has been sent. One big downer is you can only send one asynchronous email at a time -- if you're currently waiting for a previous SendAsync call to finish, other Send or SendAsync calls will fail. Which sortof sucks.

// Send an email without waiting for completion
mySMTPClient.SendCompleted += new SendCompletedEventHandler(MyHandler);
mySMTPClient.SendAsync(myMessage, null);

void MyHandler(System.Object sender, AsyncCompletedEventArgs e)
{
	// code goes here to say "sending complete!" or something
}

Related links:
SmtpClient: http://msdn2.microsoft.com/en-us/library/4971yhhc(en-US,VS.80).aspx
SendAsync: http://msdn2.microsoft.com/en-us/library/x5x13z6h(en-US,VS.80).aspx
Attachment: http://msdn2.microsoft.com/en-us/library/e02kz1ak(en-US,VS.80).aspx

 

October 19, 2005    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



 Tuesday, October 11, 2005

The upcoming MSDN offerings will provide copies of Microsoft's latest and greatest, including Visual Studio 2005, Windows Vista, Team System, et al. Unfortunately, the highest-level MSDN package is $10,000 (pricing chart). Which is huge. Huge enough to make development shops look at Subversion (instead of VSS) and other alternatives. Especially when you consider that if you have a QA department, all your testers need an MSDN license in order to test software built using MSDN-licensed tools (oh yes, it's true).

One big way to get that software but save on licenses is to enroll in the Empower ISV program. For $375/year, you get 5 MSDN Universal licenses, plus a bunch of other stuff. The downside (?) is you have to actually build something using Microsoft tools, and the license is only good for a year. And you also have to take a stab at getting some people MS-certified.

October 11, 2005    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]



If you have a 32 bit application uses custom registry values (e.g. HKLM/Software/MyApp/MySetting), it might have problems accessing those keys when run on 64-bit Windows. That's because 64-bit Windows (via WOW64, the 32-bit emulator that runs on 64-bit Windows) has separate sections in the registry for 32-bit apps and 64-bit apps. So when run on 64-bit windows, if a 32-bit app is looking for

HKLM/Software/MyApp/MySetting

it actually needs to look in

HKLM/Software/WOW6432Node/MyApp/MySetting

when running on 64-bit Windows.

If you want to use the same key location regardless of which OS you're running, you need to enable registry reflection (or registry mirroring) for the keys you're interested in. WOW64 uses registry reflection to store certain keys in both the 32-bit and 64-bit registry sections. This allows 32-bit and 64-bit applications to share the same set of registry keys, and allows your application to use the same key on 32-bit and 64-bit Windows. A number of keys are reflected by default (e.g. HKLM/Software/Classes, a bunch of stuff under HKLM/Software/Microsoft), but you can use the RegEnableReflectionKey function to ask the OS to provide reflection for any key you need shared between 32-bit & 64-bit code (for example, our friend HKLM/Software/MyApp/MySetting).

More info:

http://support.microsoft.com/?kbid=305097

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/win64/win64/registry_reflection.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/win64/win64/running_32_bit_applications.asp

 

 

OS
October 11, 2005    Bookmark to Digg or other social bookmarking
#    Disclaimer  |  Comments [0]