Get Random value from Enum

Here is a small snippet for get random value from a enum.

Array values = Enum.GetValues(typeof(View));
Random random = new Random();
View randomBar = (View)values.GetValue(random.Next(values.Length));
listView_Files.View = randomBar;
Musthaan
Musthaan
Advertisements

Preview an image before it is uploaded using JS

Hi,

My colleagues many times asked this question. So i am sharing a simple method to achieve this.

HTML

<form id="form1">
   <input id="filePic" type="file" />
   <img id="imgPic" src="#" alt="" />
</form>

Javascript

function SetImage(fileInput, imgCtrl) {
   if (fileInput.files && fileInput.files[0]) {
       var reader = new FileReader();
       reader.onload = function (e) {
           imgCtrl.attr('src', e.target.result);
       }
       reader.readAsDataURL(fileInput.files[0]); 
   } 
}

$("#filePic").change(function (e) {
   SetImage(this, $("#imgPic"));
});