Archive for May, 2010

Can not Load Type – Starting the ASP.NET Web Site Admin Tool

SNAGHTMLd7e063

A beginner emailed me last night and I had forgotten about this little ditty !

When you create a NEW project and immediately try to run the Web Site Administration Tool you will get this error.

The solution is easy – BUILD FIRST !

I remember being very confused the first time I got this :)

First 3 Videos – Building Tailspin Spyworks

image

I’ve published the first three videos on a follow-a-long series on building the Tailspin  Spyworks demo application.

More Every Week !

http://www.asp.net/web-forms/samples/tailspin-spyworks

 

Technorati Tags: ,WebForms,,

Embedding the Silverlight version of the Open Media Player

image

I’m working on a Video Portal Application and have selected the Open Video Player for embedded viewing of videos.

There are many video players out there but I selected this one becuase there are SilverLight and Flash versions in the project.

Embedding is EASY !

Code Snippet
  1. <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
  2.     CodeBehind="Default.aspx.cs" Inherits="OpenPlayerSample._Default" %>
  3.  
  4. <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
  5. </asp:Content>
  6. <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
  7.     <h2>
  8.         Welcome to ASP.NET!
  9.     </h2>
  10.     <p>
  11.         To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
  12.     </p>
  13.     <p>
  14.         <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="600px" id="slp" >
  15.             <param name="source" value="./Player/SL/OVP.xap"/>
  16.             <param name="minRuntimeVersion" value="2.0.30923.0" />
  17.             <param name="onerror" value="onSilverlightError" />
  18.             <param name="background" value="black" />
  19.             <param name="MaxFrameRate" value="30" />
  20.             <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
  21.             <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a>
  22.             <param name="initparams" value=’showstatistics=true,
  23.                                             autoplay=false,
  24.                                             muted=false,
  25.                                             playlistoverlay=false,
  26.                                             theme=/Player/Themes/ShinyBlue.xaml,
  27.                                             stretchmode=Fit,
  28.                                             stretchmodefullscreen=Fit,
  29.                                             mediasource=http://misfitgeek.com/not_a_real_video.wmv’ />
  30.         </object>
  31.     </p>
  32. </asp:Content>

 

Stay tuned to my blog for more usage context in the near future.

 

Archiving your contact form data.

image

I get TONS of email from customer.

Over time, this email helps me to determine what areas in our product collection are opportunities for enhancement or improvement.

I store the email that comes from my blog contact form in folders and then search through them looking for trends periodically.

It occurred to me that, while I need to get the emails because many of them are actionable, it would be great if I could use reporting and analysis tools against the collection.

So I whipped together a sample in ASP.NET MVC

I set up a simple SQL Express database and use Visual Studio to generate an EntityDataModel for it.

I implemented the view above and an ActionResult for HttpPost events from the ContactUs view.

Code Snippet
  1. [HttpPost]
  2. public ActionResult ContactUs(Message msg)
  3. {
  4.     if (ModelState.IsValid)
  5.     {
  6.         // Same the Message in the Massages Table.
  7.         try
  8.         {
  9.            using(ContactMailEntities db = new ContactMailEntities())
  10.            {
  11.                db.AddToMessages(msg);
  12.                db.SaveChanges();                  
  13.            }
  14.         }
  15.         catch
  16.         {
  17.             // Store Failed.
  18.             return View(msg);
  19.         }
  20.  
  21.         // Send the Message in email.
  22.         if (!SendMailMessage(msg))
  23.         {
  24.             // Send Failed.
  25.             return View(msg);
  26.         }
  27.     }
  28.     else
  29.     {
  30.         return View(msg);
  31.     }
  32.  
  33.     // Success
  34.    return View("MessageSent");
  35. }

Since my view uses that model, on post back my ActioResult can just create an instance of the model and call the generated “AddToMessages” (to insert to the Messages Table)  method and pass in the Message instance from the View.

Wow – easy and elegant.

BTW the SendMailMessage method looks like this.

Code Snippet
  1. public bool SendMailMessage(Message msg)
  2. {
  3.     try
  4.     {
  5.         MailMessage mailMsg = new MailMessage();
  6.         mailMsg.To.Add("Joe@Stagner.net");
  7.         MailAddress mailAddress = new MailAddress(msg.FromEmail, msg.FromName);
  8.         mailMsg.From = mailAddress;
  9.         mailMsg.Subject = msg.Subject;
  10.         mailMsg.Body = msg.ContactMessage;
  11.  
  12.         SmtpClient smtpClient = new SmtpClient("mail.stagner.net", 2525);
  13.         System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("Joe@Stagner.net", "bingo117");
  14.         smtpClient.Credentials = credentials;
  15.  
  16.         smtpClient.Send(mailMsg);
  17.         return true;
  18.     }
  19.     catch (Exception ex)
  20.     {
  21.         return (false);
  22.     }
  23.  
  24. }

Hope someone finds it useful.

[ Full project HERE ]