Most important topics

Static Constructor A static constructor is used to initialize the static data once or performed an action to once only. A static constructor does not take access modifiers or have parameters. A static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced. User has …

UK Postcode Validation

Regular expression for JavaScript var regPostcode = /^([a-zA-Z]){1}([0-9][0-9]|[0-9]|[a-zA-Z][0-9][a-zA-Z]|[a-zA-Z][0-9][0-9]|[a-zA-Z][0-9]){1}([ ])([0-9][a-zA-z][a-zA-z]){1}$/; var result = regPostcode.test(SearchTerm); if (!result) { alert(“Please enter valid postcode”); return false; } Regular expression for C# string regPostcode = “([a-zA-Z]){1}([0-9][0-9]|[0-9]|[a-zA-Z][0-9][a-zA-Z]|[a-zA-Z][0-9][0-9]|[a-zA-Z][0-9]){1}([ ])([0-9][a-zA-z][a-zA-z]){1}”; System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex(regPostcode); if(!regx.IsMatch(address0.PostalCode)) { results.Add(new ValidationResult(String.Format(“Please enter valid postcode for {0}.”, addressRank))); } You can check the regular expression at http://www.regexplanet.com/ …

Remove illegal characters from file name or file path in c#

File cannot be saved if file name has illegal characters. So how to remove the illegal characters by a single line code as below. I use LINQ Querty for that. string fileName = “prakash C/O swami.xml”; fileName = System.IO.Path.GetInvalidFileNameChars().Aggregate(fileName, (current, c) => current.Replace(c.ToString(), string.Empty)); Now the fileName is “rakash CO swami.xml”. The code removes slash …

How to display Progress bar while page is loading

<pre> <code> protected void Page_Load(object sender, EventArgs e) { showPageLoad(); //do somthing     } private void showPageLoad() { int i=0; Response.Write(“<div id=’divTitle’>Loading(<span id=’message’>0%</span>)</div>”); Response.Flush(); for(i=5;i<=100;i=i+5) { System.Threading.Thread.Sleep(200);// any codes can be typed here outputflash(i.ToString() + “%”); Response.Flush(); } } private void removePageLoad() { ScriptManager.RegisterStartupScript(Page, this.GetType(), “deleteLoading”, “var d = document.getElementById(‘divTitle’);d.parentNode.removeChild(d);”, true);     } private void …

Export DataTable to Excel/CSV C#

protected void btnExport_Click(object sender, EventArgs e) { DataTable dtTable = new DataTable(); DataRow dtRow; dtTable.Columns.Add(“SNo”, typeof(int)); dtTable.Columns.Add(“Address”, typeof(string)); for (int i = 0; i <= 9; i++) { dtRow = dtTable.NewRow(); dtRow[0] = i; dtRow[1] = "Address " + i.ToString(); dtTable.Rows.Add(dtRow); } Response.ContentType = "Application/x-msexcel"; Response.AddHeader("content-disposition", "attachment;filename=test.csv"); Response.Write(ExportToCSVFile(dtTable)); Response.End(); } private string ExportToCSVFile(DataTable dtTable) { …

calling [Ajax.AjaxMethod()] not working

finally its resolved by using, <system.webServer> <validation validateIntegratedModeConfiguration=”false” /> <modules> <add name=”ScriptModule” preCondition=”integratedMode” type=”System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ /> </modules> <handlers> <remove name=”WebServiceHandlerFactory-Integrated” /> <add verb=”POST,GET” name=”Ajax” path=”ajax/*.ashx” type=”Ajax.PageHandlerFactory, Ajax” /> <add name=”ScriptHandlerFactory” verb=”*” path=”*.asmx” preCondition=”integratedMode” type=”System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ /> <add name=”ScriptHandlerFactoryAppServices” verb=”*” path=”*_AppService.axd” preCondition=”integratedMode” type=”System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ /> <add name=”ScriptResource” …

Country wise TimeZones SQL DB

This time zone list use only for .Net Users.. Because .Net has inbuilt class for converting date-time into UTC and UTC to specific timezone. For that, ‘TimeZone Unique Name’ should be needed which should match with Windows System TimeZone. You can download sql script from here.

404 error WCF on server

Add below lines undser System.Server / handler section. <add name=”svc-ISAPI-2.0″ path=”*.svc” verb=”*” modules=”IsapiModule” scriptProcessor=”%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll” resourceType=”Unspecified” preCondition=”classicMode,runtimeVersionv2.0,bitness32″ /> <add name=”svc-Integrated” path=”*.svc” verb=”*” type=”System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ resourceType=”Unspecified” preCondition=”integratedMode” />