Posts

Sample code to check Kentico Xperience Object alternative form.

Kentico Xperience is a powerful CMS that build from asp.net framework. The CMS have an eCommerce solution, Intranet and collaboration, Online Marketing, and Content management that make Kentico Xperience is the most popular CMS nowadays. In Kentico Objects, you can create alternative forms allow you to create different versions of existing forms. The alternative forms can then be used instead of the default form in the system's administration interface or on the live site. This is the snippet for Kentico version 8.xx to check if the page type has an alternative form. Code Behind 1: public bool CheckIfPageTypeHaveAlternativeForm(string EditFormName,string classID) 2: { 3: bool haveForm = false; 4: if (classID != "") 5: { 6: if (CMS.DocumentEngine.CMSDataContext.Current.AlternativeForms.GetSubsetWhere("FormClassID = " + classID).Count > 0) 7: { 8: var DataInfo = CMS.DocumentEngine.CMSD

JSON & DataTable in asp.net / c#

Before start you need to convert your json data to c# class. You can achieve this by using online tools like :  http://json2csharp.com/ Go to :  http://json2csharp.com/ Paste your Json data into box and click Generate Button. Copy the code generated and create Class file in your asp.net solution. After finish convert json data to c# class, Copy the code below. Example JSON Data 1: { 2: "name":"apicode", 3: "email": 4: [ 5: "apicode@gmail.com","apicode@gmail.com" 6: ], 7: "websites": 8: { 9: "home_page":"http:\/\/apicode.blogspot.com", 10: "blog":"http:\/\/apicode.blogspot.com" 11: } 12: } JSON Class after converted 1: public class Websites 2: { 3: public string home_page { get; set; } 4: public string blog { get; set; } 5: } 6: public class RootO

Javascript show clock in webpage example

Image
This example show how to insert clock on the website which is not static clock, but like a digital clock. Script for Creating Clock 1: <script type="text/javascript"> 2: function updateClock() { 3: var currentTime = new Date(); 4: var currentHours = currentTime.getHours(); 5: var currentMinutes = currentTime.getMinutes(); 6: var currentSeconds = currentTime.getSeconds(); 7: // Pad the minutes and seconds with leading zeros, if required 8: currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes; 9: currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds; 10: // Choose either "AM" or "PM" as appropriate 11: var timeOfDay = (currentHours < 12) ? "AM" : "PM"; 12: // Convert the hours component to 12-hour format if needed 13: currentHours = (currentHours &

How to make request to web service with soap message - asp.net /C#

If you have web services and want to call the web service from your c# code, you can try to use this code example. The code example uses HttpWebRequest to create a request for the web service.  Code Behind HttpWebRequest request = (HttpWebRequest)WebRequest.Create(<web service address>); request.Headers.Add("SOAPAction", "http://tempuri.org/" + <web service method>); request.ContentType = "text/xml;charset=\"utf-8\""; request.KeepAlive = false; request.Timeout = 300000; // - in millisecond. (5 minit) request.Method = "POST"; request.Credentials = CredentialCache.DefaultCredentials; byte[] byteArray = Encoding.ASCII.GetBytes(<data you want to send to webservice>); request.ContentLength = byteArray.Length; Stream s = request.GetRequestStream(); s.Write(byteArray, 0, byteArray.Length); s.Dispose();

Decrypt web.config file - asp.net

Image
This is an example of how to decrypt a web.config file in asp.net. You can refer to this post on how to encrypt web config file. The example will decrypt web config file for 3 section which is ConnectionString, AppSetting, and system.web/authentication. Front End .aspx code <br /> This is button to decrypt web config.<br /> <asp:Button ID="Button2" runat="server" Text="Decrypt Web Config" OnClick="Button2_Click" /> Code behind private static string[] sectionName = { "connectionStrings", "appSettings", "system.web/authentication" }; public static string[] SectionName { get { return sectionName; } set { sectionName = value; } } protected void Button2_Click(object sender, EventArgs e) { //decrypt UnProtectSection(); } /// <summary> /// Decrypted web conf

Check if web.config file encrypted or not.

This is an example of how to check if the web.config file is encrypted or not. Refer to this article to encrypt and decrypt the web.config file. The example will check the web.config file for 3 section which is ConnectionString, AppSetting, and system.web/authentication. Code Behind private static string[] sectionName = { "connectionStrings", "appSettings", "system.web/authentication" }; public static string[] SectionName { get { return sectionName; } set { sectionName = value; } } /// <summary> /// method to check if web config file is encrypted or not /// </summary> /// <returns></returns> private bool CheckWebConfigIfEncrypt() { bool isEncrypt = false; foreach (string a in SectionName) { Configuration config = WebConfigurationManager. OpenWebConfigu

Kentico 8.xx - Snippet to check if page type have alternative form name

This is the snippet for Kentico version 8.xx to check if page type have alternative form. Code Behind public bool CheckIfPageTypeHaveAlternativeForm(string EditFormName,string classID) { bool haveForm = false; string strEditFormName = ValidationHelper.GetString(EditFormName, ""); if (classID != "") { if (CMS.DocumentEngine.CMSDataContext.Current.AlternativeForms.GetSubsetWhere("FormClassID = " + classID).Count > 0) { var DataInfo = CMS.DocumentEngine.CMSDataContext.Current.AlternativeForms.GetSubsetWhere("FormClassID = " + classID); foreach (CMS.DataEngine.BaseInfo a in DataInfo) { string formName = ValidationHelper.GetString(a.GetValue("FormName"), ""); if (formName.Contains(strEditFormName)) { haveForm = true; break; } }