Avoid white background when iframe loads

Posted by Prince | 5:59:00 PM | | 0 comments »

Get Rid of  White Flash when iframe Loads:
                                                               To avoid white background while iframe loads, you can hides iframe until its fully loaded. You can use the following code snippets to hide iframe when its loading.
<iframe style="visibility:hidden;" onload="this.style.visibility = 'visible';" src="../iframe.html" > </iframe>
Read more ...

Get image size in Kb using c#

Posted by Prince | 5:32:00 PM | | 0 comments »


Get image size in Kb in asp.net using c#:
                                                            Use FileInfo and the Length property to measure file size.  Here is the code for  get the file size in your C# program easily.
The blow sample contain code for get image size in KB and MB.
  FileInfo fileInfo = new FileInfo(Server.MapPath("~/Images/Header.jpg"));
            double 
fileSizeKB fileInfo.Length / 1024;
            double 
fileSizeMB fileInfo.Length / (1024 1024);
Read more ...

Encryption/Decryption Using C#

Posted by Prince | 7:11:00 PM | | 0 comments »

Encryption/Decryption of a file/string using C#:
                                                   You can use the following code for Encryption/Decryption of a file or  a string. Here you can Encrypt /Decrypt a file  or a string by using the following methods. You just pass parameters as input in to that methods and you got suitable output.
Decrypt File-to-File
Encrypt File-to-File
Encrypt String-to-File
Decrypt File-to-String
Code:
using System;
using 
System.Collections.Generic;
using 
System.Text;
using 
System.Security.Cryptography;
using 
System.IO;

namespace 
BHI.Rats
{
    
/// <summary>
    /// RatsEncryptionManager is responsible for encrypting and decrypting the files.
    /// </summary>
    
public static class  RatsEncryptionManager
    {
        
private const string passKey "c0ntr0l1";

        
/// <summary>
        /// Decrypts the input file (strInputFileName) and creates a new decrypted file (strOutputFileName)
        /// </summary>
        /// <param name="strInputFileName">input file name</param>
        /// <param name="strOutputFileName">output file name</param>
        
public static void DecryptFiletoFile(string strInputFileName, string strOutputFileName)
        {
            
string strFileData "";
            using 
(FileStream inputStream = new FileStream(strInputFileName, FileMode.Open, FileAccess.Read))
            {
                DESCryptoServiceProvider cryptic 
= new DESCryptoServiceProvider();

                
cryptic.Key ASCIIEncoding.ASCII.GetBytes(passKey);
                
cryptic.IV ASCIIEncoding.ASCII.GetBytes(passKey);

                
CryptoStream crStream = new CryptoStream(inputStream, cryptic.CreateDecryptor(), CryptoStreamMode.Read);

                
StreamReader reader = new StreamReader(crStream);

                
strFileData reader.ReadToEnd();

                
reader.Close();
                
inputStream.Close();
            
}

            
if (File.Exists(strOutputFileName))
            {
                File.Delete(strOutputFileName)
;
            
}
            
using (StreamWriter outputStream = new StreamWriter(strOutputFileName))
            {
                outputStream.Write(strFileData, 
0, strFileData.Length);

                
outputStream.Close();
            
}

        }
        
/// <summary>
        /// Encrypts the input file(strInputFileName) and creates a new encrypted file(strOutputFileName)
        /// </summary>
        /// <param name="strInputFileName">input file name</param>
        /// <param name="strOutputFileName">output file name</param>
        
public static void EncryptFiletoFile(string strInputFileName, string strOutputFileName)
        {
            
byte&#91;] fileBuffer;

            using 
(FileStream inputStream = new FileStream(strInputFileName, FileMode.Open, FileAccess.Read))
            {
                fileBuffer 
= new byte&#91;inputStream.Length];

                
inputStream.Read(fileBuffer, 0, fileBuffer.GetLength(0));


                
inputStream.Close();
            
}
            
if (File.Exists(strOutputFileName))
            {
                File.Delete(strOutputFileName)
;
            
}
            
using (FileStream outputStream = new FileStream(strOutputFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                DESCryptoServiceProvider cryptic 
= new DESCryptoServiceProvider();

                
cryptic.Key ASCIIEncoding.ASCII.GetBytes(passKey);
                
cryptic.IV ASCIIEncoding.ASCII.GetBytes(passKey);

                
CryptoStream crStream = new CryptoStream(outputStream, cryptic.CreateEncryptor(), CryptoStreamMode.Write);

                
crStream.Write(fileBuffer, 0, fileBuffer.Length);

                
crStream.Close();
            
}
        }
        
/// <summary>
        /// Encrypts the input string and creates a new encrypted file(strOutputFileName)
        /// </summary>
        /// <param name="strInputString">input string name</param>
        /// <param name="strOutputFileName">output file name</param>
        
public static void EncryptStringtoFile(string strInputString, string strOutputFileName)
        {
            
if (File.Exists(strOutputFileName))
            {
                File.Delete(strOutputFileName)
;
            
}
            
using (FileStream outputStream = new FileStream(strOutputFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                DESCryptoServiceProvider cryptic 
= new DESCryptoServiceProvider();

                
cryptic.Key ASCIIEncoding.ASCII.GetBytes(passKey);
                
cryptic.IV ASCIIEncoding.ASCII.GetBytes(passKey);

                
CryptoStream crStream = new CryptoStream(outputStream, cryptic.CreateEncryptor(), CryptoStreamMode.Write);

                byte
&#91;] buffer ASCIIEncoding.ASCII.GetBytes(strInputString);

                
crStream.Write(buffer, 0, buffer.Length);

                
crStream.Close();
            
}
        }
        
/// <summary>
        /// Decrypts the input file (strInputFileName) and creates a new decrypted file (strOutputFileName)
        /// </summary>
        /// <param name="strInputFileName">input file name</param>
        
public static string DecryptFiletoString(string strInputFileName)
        {
            
string strFileData "";
            using 
(FileStream inputStream = new FileStream(strInputFileName, FileMode.Open, FileAccess.Read))
            {
                DESCryptoServiceProvider cryptic 
= new DESCryptoServiceProvider();

                
cryptic.Key ASCIIEncoding.ASCII.GetBytes(passKey);
                
cryptic.IV ASCIIEncoding.ASCII.GetBytes(passKey);

                
CryptoStream crStream = new CryptoStream(inputStream, cryptic.CreateDecryptor(), CryptoStreamMode.Read);

                
StreamReader reader = new StreamReader(crStream);

                
strFileData reader.ReadToEnd();

                
reader.Close();
                
inputStream.Close();
            
}

            
return strFileData;
        
}
    }
}
Read more ...

CSS Buttons

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

Create buttons with pure css:

The following buttons created by using only css. But it look like  an image button, here you can see a fading effect while mouse over the button. You can copy and use bellow code for css button with fading effect
<style type="text/css">
            
.button {
                font
:normal 18px sans-serif;
                text-decoration
:none;
                padding
:2px 12px 3px 12px;
                cursor
:pointer;
                position
:relative;
                overflow
:hidden;
                vertical-align
:middle;
                margin
:0 8px;
            
}
            a
.button {
                display
:inline-block;
                padding
:3px 14px 4px 14px;
            
}
            
.button span {
                position
:relative;
            
}
            
.style {
                color
:#92c564;
                border
:1px solid #111;
                background
:#2e2f31;
                background
:-moz-linear-gradient(top, #45494d, #161616);
                background
:-webkit-gradient(linear, left top, left bottom, from(#45494d), to(#161616));
                text-decoration
:none;
                -moz-border-radius
:4px;
                -webkit-border-radius
:4px;
                -moz-box-shadow
:rgba(0,0,0,.4) 0 0 8px;
                -webkit-box-shadow
:rgba(0,0,0,.4) 0 0 8px;
                text-shadow
:rgba(255,255,255,.6) 0 0 16px;
                -moz-transition
:all .2s linear;
                -webkit-transition
:all .2s linear;
            
}
            
.style span {
                position
:relative;
                z-index
:1;
            
}
            
.style .gradient {
                display
:block;
                width
:280%; height:280%;
                position
:absolute;
                bottom
:-150%;
                left
:-10%;
                background
:-moz-radial-gradient(center center, ellipse cover, rgba(255,255,255,0), rgba(255,255,255,0) 60%, rgba(255,255,255,.15) 61%, rgba(255,255,255,0));
                background
:-webkit-gradient(radial, 112 128, 0, 112 128, 196, from(rgba(255,255,255,0)), color-stop(60%, rgba(255,255,255,0)), color-stop(61%, rgba(255,255,255,.15)), to(rgba(255,255,255,0)));
                z-index
:4;
            
}
            button
.style .gradient {
                bottom
:-145%;
                left
:-17%;
                background
:-moz-radial-gradient(center center, ellipse cover, rgba(255,255,255,0), rgba(255,255,255,0) 60%, rgba(255,255,255,.14) 61%, rgba(255,255,255,0));
            
}
            
.style:hover, .style:focus {
                color
:#c5e4a9;
                text-shadow
:rgba(255,255,255,1) 0 0 12px;
            
}
        <
/style>
You can call the css class for any links and buttons in your page.
  <input value="Input" class="button style" type="button">
        
<button class="button style"><b class="gradient"></b><span>Button</span></button>
        
<a href="#" class="button style"><b class="gradient"></b><span>Anchor</span></a>
Live Sample:(Mouse over to feel difference)

  Anchor
Read more ...

Get stored procedure count in sql server

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


Some Important  SQL Queries:

                                     The following SQL queries  are very much used to my one of  a stored procedure based .net project. It may useful you too.


Get stored procedure count from a sql table:

SELECT count(*) SPCOUNT FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE='PROCEDURE'
Get number of function from a sql table:
SELECT count(*) FUNCTIONCOUNT FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE='FUNCTION'
Get all stored procedure name from a sql table:
SELECT name AS spname
FROM sysobjects
WHERE (xtype 'p'AND (name NOT LIKE 'dt%')
ORDER BY name 
Get all table name in a sql database:
Select table_name from information_schema.tables
where table_type='Base table' order by table_name 
Get stored procedure(s) for a sql table:
SELECT DISTINCT so.name
FROM 
syscomments sc
INNER JOIN sysobjects so ON sc.id=so.id
WHERE 
sc.TEXT LIKE '%table name%'
Read more ...

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 ...

Related Posts Plugin for WordPress, Blogger...