Tuesday 11 June 2013

Restricting File upload box type

<!-- Match all image files (image/*) -->
<input type="file" accept="image/*">

<!-- Match all video files (video/*) -->
<input type="file" accept="video/*">

<!-- Match all audio files (audio/*) -->
<input type="file" accept="audio/*">

<!-- Match all image files (image/*) and files with the extension ".someext" -->
<input type="file" accept=".someext,image/*">
<!-- See note below -->

<!-- Match all image files (image/*) and video files (video/*) -->
<input type="file" accept="image/*,video/*">
<!-- See note below -->


The accept attribute may be specified to provide user agents with a hint of what file types will be accepted.
If specified, the attribute must consist of a set of comma-separated tokens, each of which must be anASCII case-insensitive match for one of the following:

The string audio/*

  • Indicates that sound files are accepted.

The string video/*

  • Indicates that video files are accepted.

The string image/*

  • Indicates that image files are accepted.

valid MIME type with no parameters

  • Indicates that files of the specified type are accepted.

A string whose first character is a U+002E FULL STOP character (.)

  • Indicates that files with the specified file extension are accepted.

Tuesday 12 February 2013

Hashing

using System.Security.Cryptography;
private string GetHash(string text, string passwordFormat)
    {
        HashAlgorithm _algorithm;
        switch (passwordFormat.ToUpper())
        {
            case "MD5":
                _algorithm = MD5.Create();
                break;
            case "SHA1":
                _algorithm = SHA1.Create();
                break;
            case "SHA256":
                _algorithm = SHA256.Create();
                break;
            case "SHA512":
                _algorithm = SHA512.Create();
                break;
            default:
                throw new ArgumentException("Invalid password format.", "passwordFormat");
        }
        byte[] bytes = Encoding.UTF8.GetBytes(text);
        byte[] hash = _algorithm.ComputeHash(bytes);
        string hashString = string.Empty;
        foreach (byte x in hash)
        {
            hashString += String.Format("{0:x2}", x);
        }
        return hashString.ToLowerInvariant();
    }

Sunday 4 March 2012

Reverse string in asp.net C#


        string a = "Vinay";
        char[] strArray = a.ToCharArray();
        Array.Reverse(strArray);
        string strReversed = new string(strArray);
        Response.Write(strReversed);

Output:
yaniV

Friday 21 October 2011

Solution for Pageindex error on datagrid bind

if (DT.Rows.Count > 0)
               {
                   try
                   {
                       DataView dvCompanyName = new DataView(DT);
                       grdProductList.DataSource = dvCompanyName;
                       grdProductList.DataBind();
                   }
                   catch (Exception ex)
                   {
                       if (!(grdProductList.CurrentPageIndex < grdProductList.PageCount))
                       {
                           if (!(grdProductList.PageCount == 0))
                           {
                               grdProductList.CurrentPageIndex = grdProductList.PageCount - 1;
                               grdProductList.DataBind();
                           }
                       }
                       else
                       {
                           grdProductList.DataBind();
                       }
                   }
               }

Wednesday 14 September 2011

Comparing Arrays(Finding Unique Values by comparing arrays)

 string[] Array1 = { "Vinay", "Pradeep", "Manoj", "Nimesh", "Sandy", "Viren", "Suresh" };
 string[] Array2 = { "Vinay", "Pradeep", "Manoj", "Nimesh", "Sandy" };

        foreach (string nextRole in Array1)
        {
            int position = Array.IndexOf(Array2, nextRole);
            if (position < 0) // change it to > if u want common values from both arrays)
            {
                Response.Write(nextRole + "<br/>");
            }
        }

========================

Output:
Viren
Suresh
===============

Monday 6 June 2011

Alertbox from codebehind(C#)

Code:
public void Say(string msg)
    {
        string popupScript;
        popupScript = "<script language='javascript'>alert('" + msg + "');</script>";
        ClientScript.RegisterStartupScript(this.GetType(), "popupScript", popupScript);
    }

Calling:
 Say("Please Select a Subject");



Friday 3 June 2011

Hello world!!

Hi,

Greetings!!!

This is my first post of this blog..I will keep updating the blog with small scale utilities used in day-to-day programming.

Be online..