Mar 7, 2012

Disable Double Click Asp.net Button

How to Prevent Double click in Asp.net

The following snippets will prevent you from the Double click 


 Just use the below line code under page_load event:

cmdSubmit.Attributes.Add("onclick", "this.disabled=true;" + ClientScript.GetPostBackEventReference(cmdSubmit,"").ToString());

note:-  cmdSubmit should be Asp.net Button Name

Jan 24, 2012

How to Read all blob list from the Windows Azure Storage Containers

Read all Blob List Names from the Windows Azure Containers


The Following snippets is used to read all the Blob list details from the azure containers
and also we can avoid the transport connection error while reading the huge blob list.
by the paging segment concept can able to read large no of blob list...
       
 
              ///////// Getting Blobs List if it's below than 5000 ///////////  
 
             TextWriter  tw = new  StreamWriter ("d:/blob_thumblist.txt" );            
             int  pagingCount = 1000;
             CloudStorageAccount  storageAccount = CloudStorageAccount .Parse(ConfigurationSettings .AppSettings["CloudStorage" ].ToString());
             CloudBlobClient  blobClient = storageAccount.CreateCloudBlobClient();
             //Get a reference to the container. 
             CloudBlobContainer  container = blobClient.GetContainerReference("ContainerName" );
  
             ///////// Getting Blobs if's below than 5000 ///////////  
 
             //Return blobs using a flat listing. 
             BlobRequestOptions  options = new  BlobRequestOptions ();
             options.UseFlatBlobListing = true ;
 
             ////This first operation will return up to 5000 blobs. 
             ResultSegment <IListBlobItem > resultSegment = container.ListBlobsSegmented(options);
             foreach  (var  blobItem in  resultSegment.Results)
             { 
                 //writing the blob name into the text file  
                 tw.WriteLine(blobItem.Uri.Segments[2]);
             }
             //close the stream 
             tw.Close();
 
   
           ///////// Getting Blobs List if it's more  than 5000 /////////// 
 
             TextWriter  tw = new  StreamWriter ("d:/blob_thumblist.txt" ); 
             int  pagingCount = 1000;
             CloudStorageAccount  storageAccount = CloudStorageAccount .Parse(ConfigurationSettings .AppSettings["CloudStorage" ].ToString());
             CloudBlobClient  blobClient = storageAccount.CreateCloudBlobClient();
             //Get a reference to the container. 
             CloudBlobContainer  container = blobClient.GetContainerReference("ContainerName" );
             ///////// Getting Blobs if's more  than 5000 /////////// 
 
             ResultContinuation  continuationToken = resultSegment.ContinuationToken;
 
             //Check whether there are more results and list them in pages of 1000. 
             while  (continuationToken != null )
             {
                 resultSegment = container.ListBlobsSegmented(pagingCount, continuationToken, options);
                 foreach  (var  blobItem in  resultSegment.Results)
                 {
                     //writing the blob name into the text file  
                     Console .WriteLine(blobItem.Uri.Segments[2]);                           
                 }
         
                 //getting blob list count per Paging 
                 Console .WriteLine(resultSegment.Results.Count());
                 //Console.ReadLine(); 
                 continuationToken = resultSegment.ContinuationToken;
                 //calling next set of blob list 
                 resultSegment.GetNext();
        
             }
 
              //close the stream 
             tw.Close();
 

Jan 6, 2012

How to Check Azure Blob List Exist or Not

Check Blob List Exist or Not

use the following snippet to check whether the blob is Exist or not
   
public  static  bool  Exists(this  CloudBlob  blob)
         {
             try 
             {
                 blob.FetchAttributes();
                 return  true ;
             }
             catch  (StorageClientException  e)
             {
                 if  (e.ErrorCode == StorageErrorCode .ResourceNotFound)
                 {
                     return  false ;
                 }
                 else 
                 {
                     throw ;
                 }
             }
         }
 

Jul 21, 2011

Disable Browser Back Button using csharp

Disable Firefox and IE Back Button in Asp.net


public void ClearBrowserCache(){      HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); 
HttpContext.Current.Response.Cache.SetExpires(DateTime.Now); HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
      HttpContext.Current.Response.Cache.SetNoStore();
     }

call this method in each and every page load Event.

note:This functionality will not work when you call Server.Transfer for page redirection.

Jul 4, 2011

The remote certificate is invalid

The remote certificate is invalid according to the validation procedure


you will get this error because of certificates issue while getting the response from the external web service or any other Web Request from the server.

follow the below snippet to resolve this issue

using System.Net;

using System.Net.Security;

using System.Security.Cryptography.X509Certificates;

protected void Page_Load(object sender, EventArgs e)

    {

      ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCB;

      Uri uri = new Uri("http://microsoft.com");

      if (uri.Scheme == Uri.UriSchemeHttp)

     {

       HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);

       request.Method = WebRequestMethods.Http.Get;

       HttpWebResponse response = (HttpWebResponse)request.GetResponse();

StreamReader reader = new StreamReader(response.GetResponseStream());     

       string tmp = reader.ReadToEnd();

Response.Write(tmp);

       response.Close();

               

     }

       

    }

public static bool RemoteCertificateValidationCB(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

    {

        //If it is really important, validate the certificate issuer here.

        string resultsTrue = certificate.Issuer.ToString();

        //For now, accept any certificate

        return true;

    }




Jan 5, 2011

Insert single apostrophe in sql server varchar datatype

Single Apostrophe  in Sql server

If you are using SQL strings in your database , chances are you have come across problem with strings in SQL statement. One extra apostrophe screws up the SQL string, causing the SQL statement to fail.

if you  insert the  following query it throws the error like below

insert into emp values('gurucoder's')

Error:

Msg 102, Level 15, State 1, Line 1


Incorrect syntax near 's'.

Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark after the character string ')
'.


After some googled i found the solution to solve this .putting the double apostrophe in string value

insert into emp values('gurucoder''s')
 
The above query with double apostrophe will insert the values like gurucoder's in database field

csproj is not installed error

csproj is not installed error Make sure the application for the project type (.csproj) is installed

This error occurs when u attempt to open the old visual studio project in new Version IDE...
there is no need to reset the enviroment settings and unistall the IDE .To solve this error follow the solution







solution:


Go to Run command type the below :

devenv.exe /resetskippkgs

perhaps i'm faced this error and i used the above solution it perfectly works within a minute............... 

Twitter Delicious Facebook Digg Stumbleupon Favorites More