Adsence750x90

Monday, August 24, 2009

Create Error Log in ASP.NET - Exception handling

How to log your errors in asp.net C#

There are many methods to log errors for example send errors via mail or keep in text file. This is an example to how to log errors in text file.

Class file to save Exception.

In this class there is one function ErrorLog parameter of error log is Exception
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public class LogError
{
public LogError()
{
public static void ErrorLog(Exception er)
{
try
{
string path = HttpContext.Current.Server.MapPath("errorlog.txt");
if (!System.IO.File.Exists(path))
{
using (System.IO.StreamWriter sw = System.IO.File.CreateText(path))
{
sw.WriteLine("Error :" + DateTime.Now.ToString());
sw.WriteLine(er.Source + er.Message + er.StackTrace);
sw.WriteLine("******************************************************");
}
}
else
{
using (System.IO.StreamWriter sw = System.IO.File.AppendText(path))
{
sw.WriteLine("Error :" + DateTime.Now.ToString());
sw.WriteLine(er.Source + er.Message + er.StackTrace);
sw.WriteLine("******************************************************");
}
}
}
catch
{
}
}
}

Wednesday, August 12, 2009

d3dx9_34.dll was not found - Installation Error

This is a common error when we installing some software like games in Windows XP / Vista.
we can fix this bug by installing DirectX.

You can download DirectX 10 click here
Alternate Link

Saturday, August 1, 2009

How to Strip (Remove) HTML tag from a String Using ASP.NET C# - using regular expression

How to Strip (Remove) HTML tag from a String Using ASP.NET C#

Using regular Expressions we can strip HTML Contents from a string. System.Text.RegularExpressions namespace conatin regular expressions in asp.net.
Replaces all occurrences of a pattern defined by a specified regular expressionwith a specified replacement character string, starting at the first character in the input string. Options can be specified to modify matching behavior.

Syntax

1: Regex.Replace(string input, string pattern, string replacement);
2: Regex.Replace(string input, string replacement, int count, int startat);
3: Regex.Replace(string input, string pattern, MatchEvaluator evaluator, RegexOptions options);

Example

string pattern = @"<(.|\n)*?>";
string withOutHtml=Regex.Replace("html content",pattern,string.Empty,RegexOptions options);