Embedding Code Snippets (Syntax Highlighting) - Blog Engine

by Nathan 1. August 2011 10:03

Here a few pages that will explain how to setup syntax highlighting in Blog Engine:

 

http://syntaxhighlighter.codeplex.com/wikipage?title=supported%20CSS%20classes&referringTitle=Home

http://blogengine.codeplex.com/discussions/19668?ProjectName=blogengine

http://rtur.net/blog/post/2007/11/Insert-Code---your-options.aspx

http://www.manoli.net/csharpformat/

http://www.microsoft.com/web/solutions/code-embed.aspx

Tags: , ,

ASP.NET

Sending Emails through gmail SMTP Server using C# ASP.NET

by Nathan 8. December 2010 09:48

Here is the C# code to send emails through the gmail smtp server. You will need to replace the emailaddress and password to reflect your gmail account.

NOTE: Headers will be replaced by gmail that will make your from address @gmail.com

 

 

 

using System;
using System.Configuration;
using System.Net;
using System.Net.Mail;


public class GmailSMTP
{

    public bool Send(string fromEmail, string senderName, string[] toEmail, string[] cc, string[] bcc, string emailSubject, string emailContent, bool isHtmlContent, out string sendStatusMsg)
    {
        bool inValidEmailAddr = false;
        string outPutParam = "";


        if (fromEmail == "" || fromEmail == null)
        {
            sendStatusMsg = "(From) Email Address cannot be null.";
            return false;
        }

        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();
        MailAddress fromAddress = new MailAddress(fromEmail, senderName);

        // SMTP Details
        smtpClient.Host = "smtp.gmail.com";
        smtpClient.Port = 587;
        smtpClient.EnableSsl = true;
        smtpClient.UseDefaultCredentials = true;
        NetworkCredential SMTPUserInfo = new NetworkCredential("youraddress@gmail.com", "password");
        smtpClient.Credentials = SMTPUserInfo;
        message.From = fromAddress;

        foreach (string toAddr in toEmail)
        {
            message.To.Add(toAddr);
        }

        if (cc != null)
        {
            foreach (string ccAddr in cc)
            {
                message.CC.Add(ccAddr);
            }
        }

        if (bcc != null)
        {
            foreach (string bccAddr in bcc)
            {
                message.Bcc.Add(bccAddr);
            }
        }

        message.Subject = emailSubject;
        message.IsBodyHtml = isHtmlContent;
        message.Body = emailContent;
        try
        {
            smtpClient.Send(message);
            sendStatusMsg = "Message sent successfully";
            return true;
        }
        catch (Exception ex)
        {
            sendStatusMsg = "Send Email Failed: " + ex.Message;
            return false;
        }
    }

}

 

Tags: ,

ASP.NET

Attempted to access an unloaded AppDomain

by Nathan 1. March 2010 07:55
Problem occured when running application in debug mode, have resolved by restarting Visual Studio 2005.

Tags:

ASP.NET

Clearing All Textbox Programatically in ASP.NET Web Form

by Nathan 15. July 2009 11:04

There are multiple ways of doing this ie using JavaScript, but this is the server side solution.

You can adapt this method for several other solutions:

        foreach (Control c in this.Page.Controls)
        {                        
            if(c.GetType().FullName.Equals("System.Web.UI.HtmlControls.HtmlForm")) {
                foreach (Control cForm in c.Controls)
                {                        
                    if(cForm.GetType().Equals(typeof(TextBox))) {   
                        ((TextBox)(cForm)).Text = "";
                    }
                }
            }
        }

Tags:

ASP.NET

Selecting Default Values on Dropdown Lists

by Nathan 2. June 2009 10:17

If you would like your application to set the selected item in your dropdownlist to an item from a variable passed to it, or from the database

Here are some examples:

 

ASP.NET 

<asp:DropDownList ID="DropDownList1" runat="server"/><br />

DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(value.ToString()));

 

VBScript ASP Example:

 

  response.write "<select size=""1"" name=""selectData"" id=""selectData"">"
  response.write "<option value='0'>-- Select  Data --</option>"
  do while not objRs.eof

      if (ContactType = objRS("Value")) then
          response.write "<option value='"+cstr(objRS("Value"))+"' selected>"+objRS("Description")+"</option>"
      else
          response.write "<option value='"+cstr(objRS("Value"))+"'>"+objRS("Description")+"</option>"
      end if

      objRs.MoveNext
  loop
  response.write "</select></font></p>"

 

If you have a lot of variables i suggest using a for loop:

 

    response.write "<select name='select1'>"

    Dim MyWebSiteArray
    PrefOddsArray = MyWebSiteArray("web design","design","website","nathan","baker")

    For each Item in MyWebSiteArray

   DatabaseValue = RS("ValueFromDatabase")


   if(DatabaseValue = Item)  then
        response.write "<option value="""+Item+""" selected>"+Item+"</option>\n"
    else
        response.write "<option value="""+Item+""">"+Item+"</option>\n"
    end if
    Next
    response.write "</select></td>"
    response.write "</tr>"

 

 

Tags: , , ,

ASP | ASP.NET

Unable to cast object of type 'System.Web.Configuration.ScriptingAuthenticationServiceSection' to type 'System.Web.Configuration.ScriptingAuthenticationServiceSection'.

by Nathan 29. March 2009 08:42

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: The entry 'ScriptModule' has already been added.

Source Error:

<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>


This happens when the config for a virtual directory is already defined in the root web application

There are two ways you can fix this:

<remove name="ScriptModule" />

Alternatively you can stop the  the web.config inheritance to the the virtual directory.
by adding this to the parent web.config

    <location path="." inheritInChildApplications="false">
    <system.web>
    ...
    </system.web>
    </location>

 

I found out that the root application had .NET 3.5 references in the web.config

I tried to remove this using:

    <location path="." inheritInChildApplications="false">
    <system.web>
    ...
    </system.web>
    </location>


the problem actually occured due to the  3.5 reference in the <configSections>

Tags:

ASP.NET

Inheritance issues in web.config

by Nathan 17. February 2009 17:14

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: The entry 'ScriptModule' has already been added.

Source Error:

<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>


This happens when the config for a virtual directory is already defined in the root web application


There are two ways you can fix this:

<remove name="ScriptModule" />

Alternatively you can stop the  the web.config inheritance to the the virtual directory.
by adding this to the parent web.config

    <location path="." inheritInChildApplications="false">
    <system.web>
    ...
    </system.web>
    </location>


--------------------------

I also came upon this problem when trying to fix this issue:

Unable to cast object of type 'System.Web.Configuration.ScriptingAuthenticationServiceSection' to type 'System.Web.Configuration.ScriptingAuthenticationServiceSection'.

which led me to realise there were .NET 3.5 references in the parent application's web.config

I tried to remove this using:

    <location path="." inheritInChildApplications="false">
    <system.web>
    ...
    </system.web>
    </location>

the problem actually occured due to the 3.5 reference in the <configSections>

Tags:

ASP.NET

Powered by BlogEngine.NET 1.6.1.0
Theme by Mads Kristensen