Check if file exists using C#

Posted by Prince | 8:35:00 PM | | 0 comments »


C# File.Exists Method:

Exists method of the System.IO.File class can be used to check if a file exists in a given location.


Code:
private static bool IsFileExists(stringsFileName){
 try
 {
   if (File.Exists(sFileName) == true)
   {
     return true;
   }
   else
   { 
     return false;
   }
 }
 catch (Exception ex)
 {
   Console.WriteLine(ex.Message);
   return false;
 }
}
Read more ...

Find out and display a user's screen resolution with javascript.
In javascript, the screen.width and screen.height properties contain the size a visitor's monitor is set to.
This can be useful if you have a page designed for a screen resolution that is higher than some viewers may have available

The following javascript function  is used to get your system screen resolution.

<head>
 
<title>Get Screen Resolution</title>
<script type="text/javascript" language="javascript">
function scrResolution(){
       
var width=screen.width;
        var 
height screen.height;
        document.getElementById("txt_scrWidth").value=width;
        document.getElementById("txt_scrHeight").value=height;
}
</script>

</head>
<body onload="scrResolution();">
  <table width="200" border="0">
     <tr>
       <td>     Width :
     <input name="txt_scrWidth" type="text" id="txt_scrWidth" size="5" />
      </
td>
     
</tr>
     
<tr>
       
<td>
           Height :
       <input name="txt_scrHeight" type="text" id="txt_scrHeight" size="5" />
       </
td>
     
</tr>
    
</table>
</body>
</html>

Your Screen resolution
     Width : px
     Height : px         

Read more ...

Get gmail contacts using C#

Posted by Prince | 4:27:00 PM | | 0 comments »

Import gmail contactlist using C#:
For getting started we need to download the following Google dll files and put these 3 dlls in BIN folder of your application.

1. Google.GData.Client
2. Google.GData.Contacts
3. Google.GData.Extensions

Then create an aspx file with two text boxes,one list box and a submit button (See screen shot)

Finally give your gmail user name and password to corresponding input boxes. Then click Get Contacts you will see all your gmail contacts list in Contacts box



Click here  for full code download
Read more ...

Div height not working in IE

Posted by Prince | 4:22:00 PM | | 1 comments »

Div height is different in IE:
            In one of my client project (In ruby) I need a slider control for change the light's intensity The intensity range from 0 to 100.But don't allow the user to give intensity bellow 50.This means prevent the user to move the slider bellow 50.  
           So I create two div elements,the first div contains the value 0...50 and its height is 4px(slider height) with green static background which means the user can't move the slider up to 50(a small trick!).The second div contains the original slider control and its value from 50...100.See the blow code(As per client requirement)  

<table cellpadding="0" cellspacing="0" border="0" >
     <tr>
        <td style="vertical-align: bottom; padding-bottom: 1px;">
              <div style="font-size: 10px;">0</div>
               <div id="divDummySlider" class="dummySlider">&nbsp;</div>
          </td>
           <td>
                <div id="divSlider"></div>
            </td>
       </tr>
   </table>  
With the following css             
            .dummySlider
            {
                background-color: green;
                height: 4px;
                width: 50px;
            }  
The above code work fine with all major browsers except IE. In IE the "divDummySlider" height is different from other browsers.See the image below...  
After that I found the following solution to fix div height problem in IE .Look at the  dummy slider height is mingled with original slider control height (See the image below...)   
                                                                      
Solution:             
             .dummySlider      
              {
                background-color: green;
                height: 4px;
                width: 50px;         
                overflow:hidden; 
              }  
               Just add "overflow:hidden;" property to the "divDummySlider" style.And finally I get relief from this problem.(Hope you also)  
Read more ...

Cookies handling using javascript

Posted by Prince | 8:46:00 PM | | 0 comments »

Cookies handling using javascript

This simple post explained the cookie handling including create,get and delete cookies by using javascript.In one of my ruby project I'm struggled with retained client side paging (Paging using javascript) on that time I'm using this client side cookies to over come that problem.I thing you may use this concept to client side paging,sorting,keep dropdown sclected index and other client side actions.


Code:


<script src="../cookies.js"></script>
 

Step 1: Check cookies is enabled

Before go to create cookie you have to check if the cookies are allowed.

<script type="text/javascript" language="javascript">

    
function isCookiesEnabled () {
        
if (testSessionCookie())
            
alert ("Session coookies are enabled")
        
else
            alert 
("Session coookies are not enabled");
    
}

</script>


  Click to see if session cookies are allowed:


Step 2: Create cookie:

        The next step you can give a name and value for your cookie.
 
<script type="text/javascript" language="javascript">

    
function setCookie(){

        
if (testSessionCookie()) {

               
var myName = document.getElementById('addCookiName').value;

            var 
myValue = document.getElementById('addCookiValue').value;

            
createCookie (myName, myValue);
            alert 
("Session cookie created");
        
}
        
else
        
{
            
alert ("Sorry - session cookies are currently disabled.");
        
}     

}
</script>

Demo: 

Create cookie:

Cookie name:

Cookie value:


 
Step: 3: Get value from cookies by using its name


<script type="text/javascript" language="javascript">

    
function getCookie () {
        
var myCookieName = document.getElementById('getCookiName').value;
        if 
(getCookieValue (myCookieName))
            
alert ('The value of the Cookie is "' + getCookieValue (myCookieName) + '"')
        
else
            alert 
("Cookie not found");
    
}

</script
 

Demo:

Get value from cookie by using it's name
Cookie name:

Step 4:

And finally you can delete value from cookie by using the following nethod


<script type="text/javascript" language="javascript">

    
function deleteCookies () {
        
var myCookieName = document.getElementById('deleteCookiName').value;
        if
(myCookieName !""){
            
if (!getCookieValue (myCookieName))
                
alert ('Cookie does not exist')
           
else  {
                deleteCookie(myCookieName)
;
                alert 
("Cookie deleted successfully");

            
}
        }        
else

        
{

            
alert ('Cookie does not exist')
        }

    }

</script>

Demo: 

Delete value from cookie by using it's name
Cookie name:


You can download full source code from here...
Read more ...

Related Posts Plugin for WordPress, Blogger...