Wednesday 4 November 2015

Dialog box confirmation before exit android app.

Leave a Comment
This is the code to trigger dialog box before you exit the application in android.


  private void ShowMessageExit(String Message){  
     new AlertDialog.Builder(this)  
         .setMessage(Message)  
         .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {  
           public void onClick(DialogInterface dialog, int which) {  
             android.os.Process.killProcess(android.os.Process.myPid());  
             System.exit(0);  
           }  
         })  
         .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {  
           public void onClick(DialogInterface dialog, int which) {  
             // do nothing  
           }  
         })  
         .setIcon(android.R.drawable.ic_dialog_alert)  
         .show();  
   }  



By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Saturday 3 October 2015

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

Leave a Comment
If you have webservice and want to call the web service from your c# code, you can try to use this method example.

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();  
         s.Close();  
         HttpWebResponse response = (HttpWebResponse)request.GetResponse();  
         Encoding enc = System.Text.Encoding.GetEncoding(1252);  
         StreamReader resStream = new StreamReader(response.GetResponseStream());  
         result = resStream.ReadToEnd(); // read webservice response
         dataToSend = "";  
         resStream.Dispose();  
         resStream.Close();  
         response.Close();  
         return result;  


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Method snippet to remove space between words - asp.net

Leave a Comment
This is the method that can use in c# application or asp.net to remove space between words.

Example :


Hello World  --> HelloWorld

Method 

    /// <summary>  
     /// Method to remove space in a string example : Hello world --> HelloWorld  
     /// </summary>  
     /// <param name="data"></param>  
     /// <returns></returns>  
     public static string removeSpace(string data)  
     {  
       Regex r = new Regex(@"\s+");  
       string _temp = "";  
       _temp = r.Replace(data, @"");  
       return _temp;  
     }  

OR without static

    /// <summary>  
     /// Method to remove space in a string example : Hello world --> HelloWorld  
     /// </summary>  
     /// <param name="data"></param>  
     /// <returns></returns>  
     public string removeSpace(string data)  
     {  
       Regex r = new Regex(@"\s+");  
       string _temp = "";  
       _temp = r.Replace(data, @"");  
       return _temp;  
     }  




By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Check web config file either encrypt or not.

Leave a Comment
This is example how to check if web.config file is encrypt or not. refer this article to encrypt and decrypt web config file.

The example will check 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.  
             OpenWebConfiguration("~" + HttpContext.Current.Request.ApplicationPath);  
         ConfigurationSection section =  
              config.GetSection(a);  
         if (section != null &&  
            section.SectionInformation.IsProtected)  
           isEncrypt = true;  
         else  
         {  
           return false;  
         }  
       }  
       return isEncrypt;  
     }  


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

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

Leave a Comment
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;  
             }  
           }  
         }  
       }  
       return haveForm;  
     }  


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

delete top N rows mssql

Leave a Comment
This example show how to delete top N rows in mssql, where N is 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 the example number.
  • [table_name] is the table you want to delete
  • a1 is just a example of sort by column a1
Tanks 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


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

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

Leave a Comment
This is example 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"  
      }  
 }  

Read More...

How to convert JSON data to Class - C#

Leave a Comment
Today i found one very good tools to convert JSON data to c# class.

Please go to this link : http://json2csharp.com/

You just paste the json data, and it will give you the class for each element in the json data.

Example JSON Data :

Note : This example JSON data from TripAdvisor API.

  {  
  "address_obj": {  
   "street1": "Lot PTB22819 ",  
   "street2": "Jalan Skudai",  
   "city": "Johor Bahru",  
   "state": "Johor",  
   "country": "Malaysia",  
   "postalcode": "80200",  
   "address_string": "Lot PTB22819 Jalan Skudai, Johor Bahru 80200 Malaysia"  
  },  
  "latitude": "1.485111",  
  "rating": "4.0",  
  "description": "Staying true to our unique no frills concept, we provide you a good night's sleep at outstanding value. Our hotels come with high quality beds, power showers, 24-hour security system, and are conveniently located near transportation hubs and popular local attractions. Unnecessary costs are kept at bay by eliminating facilities that you might not need such as swimming pools, gyms, spa rooms etc.\n\nTune Hotel Danga Bay Johor offers easy access to Asia's first LEGOLAND(R) theme park which is 15-minutes' drive away, or you can hitch a ride with the shuttle bus provided by our hotel. Kids would love exploring the Sanrio Hello Kitty Town, Little Big Club, Thomas and Friends, and Barney at Puteri Harbour which is next to LEGOLAND(R). Daily shuttles transfers are also available to the doorstep of Resorts World Sentosa and Universal Studios Singapore. If you want to just shop, don't miss out on an exquisite shopping experience at Johor Premium Outlets!",  
  "location_id": "1770042",  
  "trip_types": [  
   {  
    "name": "business",  
    "value": "49",  
    "localized_name": "Business"  
   },  
Read More...

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.