Sunday, July 21, 2013

How to Create Wireless Ad hoc / Access Point in Windows 8

In windows 8 creating ad hoc or access point is not available in the OS, but there is a paid app in Windows App store called Wi-Fi Hotspot Creator Assistant. But no need to purchase this app to create a new Wi-Fi hotspot, because the creating an Ad Hoc is still available inside the core of the Windows, but it’s not available in GUI.

Here are the steps to create an Ad Hoc network.

  1. First open up the windows command prompt with administrator privileges. To do so search for “cmd” and right-click on it then select run as administrator from below options.

  2. Then you have to check whether the network card supports ad hoc networks to do soo run this command >netsh wlan show driver, then look at line Hosted network support

    If your network car support ad hoc then proceed with next step.

  3. Now enter following command line. Note: change the markup tags as your wish.

    netsh wlan set hostednetwork mode=allow ssid=<enter_ name_for_network>key=<enter_passowrd_here>
    • ssid- Name of the network
    •  key- passcode
  1. As the final step to start the connection enter this command netsh wlan start hostednetwork. Now you have done with creating ad hoc network
    If you having problem with starting the connection, just go to the Device manage and check whether the virtual wifi adapter is enabled under Network adapters.
    This wi-fi hotspot can be used to share the internet connection. 

    You can simply use this bat file to create a connection- Download here 

Wednesday, February 20, 2013

Replaces invalid XML characters in a string with their valid XML equivalent


Sometimes when creating XML documents with user specific data, string values of the XML nodes have to be encoded to maintain the structure of the XML nodes. Following table shows invalid XML characters and their escaped equivalent.

Invalid XML Character
Escaped equivalent
“<”
"<"
“>”
">"
“\””
"""
“\’”
"'"
“&”
“&"


There is a build-in method in .NET to achieve this called SecurityElement.Escape under the system. Security namespace.  This method accept string parameter and returns a string with invalid characters replaced.

e.g :-
      string xml = "\"node\"&"; 
      string encodedXml = System.Security.SecurityElement.Escape(xml);
      //RESULT: <node>"node"&<node>


Tuesday, February 19, 2013

How to encode JavaScript string to escape characters such as single quotes in .NET


When registering JavaScript functions or calling JavaScript functions from code behind there might me some specials characters such as single quotes, new line characters. These kinds of characters will causes for errors such as ” Unexpected identifier” , “Unterminated String constant” or “Expected ')'” type errors. To avoid these errors string encoding has to be done.

In .Net framework 4 a new method has been introduced to cater these types of errors under the System.Web.HttpUtility namespace called HttpUtility.JavaScriptStringEncode. This method does the encoding and injects necessary escape characters.

As an example, to show an alert which includes single quotes we have to use the encoding.


  string message = "The value 'x' is not allowed";

  ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Error", string.Format("alert('{0}');", message), true); // This will give an error

  ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Error", string.Format("alert('{0}');", HttpUtility.JavaScriptStringEncode(message)), true); // JavaScript encoding has been done.


Monday, February 18, 2013

ASP.Net client side validation using Page_ClientValidate


ASP.Net client side validation using Page_ClientValidate
In typical web forms validators such as required field validators, regular expression validators, etc. are using with regular asp.net controls. With validation groups part of the controls in the web form can be validate. But with some of client events such as ‘OnClientClick’ those validations may not work as intended.  In such scenarios some mechanism has to use to check the validity of the validators to avoid unnecessary post backs. For achieve this java script Page_ClientValidate() function can be used.\\
 
Page_ClientValidate() function returns true or false based on the validity of the validators in the web form.


e.g :-
   if(retValue != null && Page_ClientValidate()){  //retValue is some variable
      return true;
   }
   else{
     return false;
   }
</ code>

Page_ClientValidate function can be used to validate controls which are belong to a validation group only.


e.g :-
   if(retValue != null && Page_ClientValidate('theGroup')){  //thGroup is a validation group
      return true;
   }
   else{
     return false;
   }