Posts

Splits the camel cased input text into separate words.

Image
This is an example method to split "Camel Cased" into separated words. Example Camel Cased ThisIsOneExample TomorrowIsWhatDay ThisIsAnotherExample ASPX Page <asp:Label ID="Label1" runat="server" Text="Camel Words"></asp:Label>: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <br /> <asp:Button ID="Button1" runat="server" Text="Convert" onclick="Button1_Click" /> <br /> Preview : <asp:Literal ID="Literal1" runat="server"></asp:Literal> <br /> <p>&nbsp;</p> <p>&nbsp;</p> Code Behind protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string camelWords = TextBox1.Text; IEnumerable<string> _words = Sp

Combine / Union two dataset - C#

This method is example to combine two dataset into single dataset. This method also called Union two dataset meaning that if both dataset contains same data, the combined dataset will not included. Method Union Dataset : /// <summary> /// Creates the union of two Datasets, the values are compared for uniqueness by the given ID column name. /// </summary> /// <param name="ds1">First DataSet</param> /// <param name="ds2">Second DataSet</param> /// <param name="idColumn">ID column name</param> public static DataSet Union(DataSet ds1, DataSet ds2, string idColumn) { if (ds1 == null) { return ds2; } if (ds2 == null) { return ds1; } ArrayList addTables = new ArrayList(); // Add the new rows foreach (DataTable dt in ds2.Tables) { DataTable destTable = ds1.Tables[d

Detect browser name & version from code behind - asp.net

Image
This is example in asp.net how to detect client browser and version. The method used in this example can work after copy paste in the Visual Studio. Aspx Code <br /> <h5> <asp:Literal ID="Literal1" runat="server"></asp:Literal> </h5> <p> &nbsp;</p> <p> &nbsp;</p> Code Behind  private string SAFARI_CODE = "Safari"; private string CHROME_CODE = "Chrome"; private string IE_CODE = "IE"; private string IE_LONGCODE = "Internet Explorer"; private string GECKO_CODE = "Gecko"; private string OPERA_CODE = "Opera"; protected void Page_Load(object sender, EventArgs e) { Literal1.Text = GetBrowserClass(true); } /// <summary> /// Gets the browser specific CSS class name. /// </summary> /// <param name="includeVersion&q

Detect request is a crawler/bot - asp.net

Sometimes you want to avoid bot from crawling the page with sensitive information like phone number and email address, so you need to have a method to detect either the request is a visitors or bot.  This code snippet shows how you can determine the request is a crawler or not. Code Behind  /// <summary> /// Returns whether browsing device is search engine crawler (spider, bot). /// </summary> public bool IsCrawler() { if (HttpContext.Current != null) { HttpRequest currentRequest = HttpContext.Current.Request; return (currentRequest.Browser != null) && currentRequest.Browser.Crawler; } return false; } You can put this method under a static class and call it from the Global.asax file.

Example to remove all script block using C# code - asp.net

Image
This is example how to remove script block in HTML. This method will be very useful if you want to validate the html passed from input string do not have any script block. Example HTML have script block : <div> this is the information </div> <script>alert('Your computer have security vulnerable');</script> Example ASPX Code : Note : This html using Editor Controller in AjaxToolkit library <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </ajaxToolkit:ToolkitScriptManager> Input Text : <cc1:Editor ID="Editor1" runat="server" /> <br /> <asp:Button ID="Button1" runat="server&q

Send email in Kentico 8.xx

This is an example method to send data in Kentico 8.xx Send email method using CMS.EmailEngine; using CMS.EventLog; ::: ::: public static class CustomClass {     public static void SendEmail(string EmailTemplateCode, MacroResolver mcr,string recipients)     {         EmailMessage msg = new CMS.EmailEngine.EmailMessage();         EmailTemplateInfo eti = EmailTemplateProvider.GetEmailTemplate(EmailTemplateCode, SiteContext.CurrentSiteID);                msg.EmailFormat = EmailFormatEnum.Both;         msg.From = eti.TemplateFrom;         msg.Recipients = recipients;         msg.Subject = eti.TemplateSubject;         try         {             EmailSender.SendEmailWithTemplateText(SiteContext.CurrentSiteName, msg, eti, mcr, true);         }         catch (Exception ex)         {             EventLogProvider.LogException(ex.Source, "SendEmail", ex);         }     } } How to call method  MacroResolver mcr = new MacroResolver();  mcr.SetNamedSourceData("DomainName", "

Turn off EventLogProvider from store update/delete/insert activity in Kentico

The event log stores information about all events that occur in the system. It is useful to view logged information if unwanted behavior occurs in the system and you want to find out where the problem originates or get additional details. But, some activities you don't want to be stored in the database while you are developing a custom web part. This is the way how to turn off the for a while in your custom code block. Step by Step  Add "using CMS.Base;" Wrap your code block with this using block code. using (CMSActionContext ctx = new CMSActionContext())     {         ctx.LogEvents = false;        //your action here. } So anything code you put under the comment " Your action " will not be recorded in the Event Log table. Have a try.