Posts

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; } }

Encrypt Web.config file - asp.net

Image
This is an example of how to encrypt a web.config file in asp.net. The example will encrypt web config file for 3 section which is ConnectionString, AppSetting, and system.web/authentication. Front End .aspx Code  <br /> This is button to encrypt web config.<br /> <asp:Button ID="Button1" runat="server" Text="Encrypt Web config" OnClick="Button1_Click" /> Code Behind private static string[] sectionName = { "connectionStrings", "appSettings", "system.web/authentication" }; public static string[] SectionName { get { return sectionName; } set { sectionName = value; } } protected void Button1_Click(object sender, EventArgs e) { //encrypt ProtectSection(); } /// <summary> /// Encrypte WebConfig file for certain section /// </summary> /// &l

Delete top N rows & Truncate table data - MSSQL

This example shows how to delete top N rows in MSSQL, where N is a dynamic number. It could be 1000, 100, or 10. ;WITH CTE AS ( SELECT TOP 1000 * FROM [table_name] ORDER BY a1 ) DELETE FROM CTE 1000 is an example number. [table_name] is the table you want to delete a1 is just an example of sort by column a1 Thanks to stack overflow for this help : http://stackoverflow.com/questions/8955897/how-to-delete-the-top-1000-rows-from-a-table-using-sql-server-2008 If you want to delete all table data in the fastest way, you can use the Truncate Keyword.  The example Table name is: Analytics_Compaign TRUNCATE TABLE Analytics_Campaign; /* Reset ID to 1, normally primary key id is auto increment, so when you truncate table data, and when new data insert into database, the id will continue from what it left. This is how you reset the id to number 1 DBCC CHECKIDENT (<tablename>,RESEED,<number to set>)*/ DBCC CHECKIDENT (Analytics_Campaign,

How to read JSON Data and convert to DataTable - asp.net / C#

This is an example of how to read JSON Data using C# code. First, before you start coding, please read this post on how to convert JSON data to c# class. How to convert JSON data to Class - C# After finish convert JSON data to C# class, write this code to read your JSON data. Example JSON Data { "name":"swengineercode", "email": [ "swengineercode@gmail.com","swengineercode@gmail.com" ], "websites": { "home_page":"http:\/\/swengineercode.blogspot.com", "blog":"http:\/\/swengineercode.blogspot.com" } } JSON Class after converted public class Websites { public string home_page { get; set; } public string blog { get; set; } } public class RootObject { public string name { get; set; } public List<string> email { get; set; } public Websites websites { get; set; } }