DateTime to simple recognized string (Facebook time format)

// DateAndTime Helper
public static string GetDateAndTimeFormNow(this HtmlHelper helper, string datetime)
{
    string value = string.Empty;

    if (!string.IsNullOrEmpty(datetime))
    {
        DateTime d1 = DateTime.Now;
        DateTime d2 = Convert.ToDateTime(datetime);

        TimeSpan t = d1 - d2;

        if (t.TotalDays >= 2)
            value = Math.Round(t.TotalDays, 0).ToString() + " days ago.";
        else if (t.TotalDays >= 1)
            value = "a day ago.";
        else if (t.TotalHours >= 2)
            value = Math.Round(t.TotalHours, 0).ToString() + " hours ago.";
        else if (t.TotalHours >= 1)
            value = "an hour ago.";
        else if (t.TotalMinutes >= 2)
            value = Math.Round(t.TotalMinutes, 0).ToString() + " minutes ago.";
        else
            value = "a minute ago.";
    }

    return value;
}

Download a file from page via HTTPS(SSL)

string _path = Server.MapPath(ConfigurationSettings.AppSettings["path"]);

if (File.Exists(_path))
{
    string data = File.ReadAllText(_path);

    byte[] byteArr = Encoding.UTF8.GetBytes(data);
    MemoryStream stream = new MemoryStream(byteArr);

    // downloading file via HTTPS(SSL) will not work w/o clearing resposne.
    Response.ClearHeaders();
    Response.ClearContent();
    Response.Clear();
    Response.AddHeader("Content-Disposition",
                       "attachment; filename=" + Path.GetFileName(_path) + "\"");
    Response.AddHeader("Content-Length", byteArr.Length.ToString());
    Response.ContentType = "application/octet-stream";
    Response.BinaryWrite(byteArr);
    Response.End();
}

Xml to DropDownList

Sample of xml file.

<?xml version=”1.0″ encoding=”utf-8″  ?>
<unitedstates>
    <state id=”AL” name=”AL – Alabama” />
</unitedstates>

ASP code

<asp:DropDownList ID=”ddlState” runat=”server” />

Code behind

XmlDataSource xml = new XmlDataSource();
xml.DataFile = Server.MapPath(“States.xml”);

ddlState.DataSource = xml;
ddlState.DataValueField = “id”;
ddlState.DataTextField = “name”;
ddlState.AppendDataBoundItems = true;
ddlState.DataBind();

SMTP Setup

    <system.net>
        <mailSettings>
            <smtp from=”noreply@domain.com“>
                <network host=”<hostname>” userName=”” password=”” />
            </smtp>
            <!– Save Email on your local machine
            <smtp from=”noreply@domain.com” deliveryMethod=”SpecifiedPickupDirectory”>
                <specifiedPickupDirectory pickupDirectoryLocation=”C:\emails\”/>
            </smtp>
            –>
        </mailSettings>
        <defaultProxy useDefaultCredentials=”true” />
    </system.net>