February 2014 | Coding Cluster - using asp.net, c#, mvc 4, iphone, php, ios, javascript, in asp.net mvc 3 & more
 

C#:Remove Special Characters from Text box in ASP.Net

Thursday

Asp.net C# - Replace all special characters from string:        
                                                                                                 "Input string was not in correct format" more or less all the .net programmers facing this issue at least one time in his carrier. Most of the times this issue caused by special characters mingle in data base query and it may entered via input controls. For example single quotes(') in address like "Peter's Road" in that time the SQL query binding with error due to that single quotes.

                         

In this case we need to replace the  special characters from the  input values that produce this error.  In c# the "String.Replace" method used to replace the string values. Here You can replace the user input's  special characters by using the following c# method.

        public static string ReplaceSpecialCharacters(string strInput)        {
            strInput = strInput.Replace("--", "++");
            strInput = strInput.Replace('&', ',');
            strInput = strInput.Replace("%", "[%]");
            strInput = strInput.Replace('+', ',');
            strInput = strInput.Replace("_", "[_]");
            strInput = strInput.Replace("[", "[[]");
            strInput = strInput.Replace("]", "[]]");
            strInput = strInput.Replace("'", "''");
            return strInput;
         }
Just send your input control value as parameter:
string txtAddress = StringHelper.ReplaceSpecialCharacters(txtAddress.Text.Trim());

Get parameters value from .exe files using ASP.NET C#

Tuesday

                                                                                    In one of my project my clients requirements is scanning a document from local scanner and directly upload into the server through web application. But there is no direct method to access local machine from sever code in dot net, so we need some other solutions to access local .exe (to activate scanner) file from server.

Finally Google answering me "ActiveX0bject". Yes we can run .exe file from server by using ActiveX shell command. Here is the sample code to run client's side .exe file from server  by using JavaScript and ActiveX0bject.

Enable ActiveX controls in IE for run .exe files from local :
                                Before  we enable ActiveX in IE settings with the following simple steps, 
Step -1:  Open IE -->Tools --> Internet Options

Step -2:  Go to security tab choose your zone (Internet (OR) Local)  then click custom Level button

Step-3:  Just set "The Initialize and script ActiveX controls not marked as safe" as "Prompt"

          



 And the following JavaScript code is for run .exe (In my case "ImageScanner.exe")file with parameter session id, display order  and user id.

JavaScript Code 

function runScaningApp(sessId, disorder, userId){

var shell=new ActiveX0bject("WScript.shell");

var res = shell.run('"ImageScanner.exe" "'+ sessId +'" "'+ disorder+'" "'+ userId+'", '1', true);

 if (res == "0"){
   alert ("Your success message");
 }
 else{
   alert ("Sorry! Some error occurred");
 }
}

Finally the following c# code for accessing the .exe's param value. Use this code in your .exe's  .cs file 

public class scanner :system.Windows.Forms.Form, IMessageFilter{

private string sessionId;
private string disorder;
private string userId;

 public Scanner (string[args){
  sessionId = args [0];
  disorder= args [1];
  userId = args [2];
 }
}

Code for pure css menu

An attractive mouse hover menu using CSS only:                      
                                                                 One of the fundamental things in web design in reference to usability is navigation. Navigation menus are important to help the user find the information that he or she seeks. Use of colors, highlights and mouse-over effects will facilitate detection of the items that are being searched. 

In this post  I give cool css only menu. The items background change with rounded corner when mouse hover .  This menu build with css and 'UL' tag only. Just copy and paste the  following html code to build this  cool menu.


<html>
<head>
<style>
#topmenu {
 float:left;
 padding-right: 20px;
 padding-left: 80px;
 padding-top: 46px;
 font-family: 'GibsonRegular'; 
}
#topmenu ul {
 display: block;
 height: 34px;
 width: 540px;
}
#topmenu ul li {
 display: block;
 float: left;
 margin-right: 5px;
}
#topmenu ul li a {
 -webkit-border-radius: 17px;
 -moz-border-radius: 17px;
 border-radius: 17px;
 -webkit-transition-property: color, border;
 -webkit-transition-duration: .2s;
 -webkit-transition-timing: ease-in;
 -moz-transition-property: color, border;
 -moz-transition-duration: .2s;
 -moz-transition-timing: ease-in;
 -o-transition-property: color, border;
 -o-transition-duration: .2s;
 -o-transition-timing: ease-in;
 transition-property: color, border;
 transition-duration: .2s;
 transition-timing: ease-in;
 display: block;
 float: left;
 font-size: 14px;
 color: #65778c;
 text-decoration: none;
 line-height: 30px;
 height: 30px;
 padding-left: 13px;
 padding-right: 13px;
 border: 2px solid transparent;
}
#topmenu ul li a.active {
 border: 2px solid #c8d8df;
 color: #DE3068;
 text-decoration: none;
}
#topmenu ul li a:hover {
 border: 2px solid #c8d8df;
 color: #DE3068;
 text-decoration: none;
}
.ie7 #topmenu ul li a, .ie8 #topmenu ul li a {
 line-height: 34px;
 height: 34px;
 padding-left: 15px;
 padding-right: 15px;
 border: none;
}
</style>
</head>
<body>
<div id="topmenu">
  <ul>
    <li><a href="#" title="Hello!" class="active"><span>Hello!</span></a></li>
    <li><a href="#" title="Portfolio"><span>Portfolio</span></a></li>
    <li><a href="#" title="Services"><span>Services</span></a></li>
    <li><a href="#" title="About us"><span>About us</span></a></li>
    <li><a href="#" title="Blog"><span>Blog</span></a></li>
  </ul>
</div>
</body>
</html>

Run client side .exe file from server side using asp.net

Saturday

                                                                   In one of my project my clients requirements is scanning a document from local scanner and directly upload into the server through web application. But there is no direct method to access local machine from sever code in dot net, so we need some other solutions to access local .exe (to activate scanner) file from server.

Finally Google answering me "ActiveX0bject". Yes we can run .exe file from server by using ActiveX shell command. Here is the sample code to run client's side .exe file from server  by using JavaScript and ActiveX0bject.

Enable ActiveX controls in IE for run .exe files from local :
                                Before  we enable ActiveX in IE settings with the following simple steps, 
Step -1: Open IE -->Tools --> Internet Options

Step -2:  Go to security tab choose your zone (Internet (OR) Local)  then click custom Level button

Step-3:  Just set "The Initialize and script ActiveX controls not marked as safe" as "Prompt"

          



 And the following JavaScript code is for run .exe (In my case "ImageScanner.exe")file with parameter session id, display order  and user id.

JavaScript Code 

function runScaningApp(sessId, disorder, userId){

var shell=new ActiveX0bject("WScript.shell");

var res = shell.run('"ImageScanner.exe" "'+ sessId +'" "'+ disorder+'" "'+ userId+'", '1', true);

 if (res == "0"){
   alert ("Your success message");
 }
 else{
   alert ("Sorry! Some error occurred");
 }
}

 
 
 

RECENT POSTS

Boost

 
Blogger Widgets