.NET ToString Format Specifiers

Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = ‘G’)
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85

Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = ‘G’)
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004

Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = ‘G’)
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003

Ways to validate Phone Numbers in C#

using System;
using System.Text.RegularExpressions;

class RegexSubstitution
{
   public static void Main()
   {
      string text = "124";

      if ( !Regex.Match(text,@"^[1-9]\d{2}-[1-9]\d{2}-\d{4}$" ).Success )
      {
         Console.WriteLine( "Invalid phone number");
      }   
   }
}

Validate Phone Number

public bool IsValidUSPhone(string number)
{
    return Regex.IsMatch(number, @"\(\d{3}\)\s\d{3}-\d{4}");
}

Matching and Grouping Regular Expressions using Regex in C#

Login failed for user ‘username’. The user is not associated with a trusted SQL Server connection.

The cause of this problem is the SQL server has been configured to operate in “Windows Authentication Mode (Windows Authentication)” and doesn’t allow the use of SQL accounts. This was the default setting in my case, I got the error after installing a new instance of SQL Server 2005.

I was able to solve this problem by changing the Authentication Mode of the SQL server from “Windows Authentication Mode (Windows Authentication)” to “Mixed Mode (Windows Authentication and SQL Server Authentication)”.

HtmlMeta Class

private void AddMetaRefresh()
{
	HtmlMeta metaValue = null;

	metaValue = new HtmlMeta();
	metaValue.Attributes.Add("http-equiv", "refresh");
	metaValue.Attributes.Add("content", Settings.AutoRefreshInterval.ToString());

	this.Page.Header.Controls.Add(metaValue);
}

App_GlobalResources maps to a directory outside this application, which is not supported.

Problem

I’ve created a very simple ASP.NET 2.0 application. I can run this with no problems using the Built-in Web Server. However, if I publish it and try running the application by typing
http://localhost/talentdata/default.aspx directly in the browser window, I get the following error:
Server Error in ‘/talentdata’ Application.
The path ‘/talentdata/App_GlobalResources’ maps to a directory outside this application, which is not supported.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The path ‘/Beta2_TEST/App_GlobalResources’ maps to a directory outside this application, which is not supported.

Solution

The solution is quite simple. I checked the IIS Default Web Site Properties -> Home Directory -> Local Path. Don’t add any “\” character at the end of the directory, so I changed the Local Path to “C:\Inetpub\wwwroot” instead of “C:\Inetpub\wwwroot\” and restarted IIS.

IIS will automatically add one thus cause problem if you manually add one before. You can check Default Web Site Properties -> ASP.NET -> File Location for actual setting information.