Allowing .exe files to be download in IIS7 and IIS8.

To Allow executable files to be download by the client just add the following configuration to web.config file.

<system.webServer>
<handlers>
<add name="StaticFile" path="*.exe" verb="*" modules="StaticFileModule" resourceType="File" />
</handlers>
</system.webServer>

Dumping Binary Content Field value into File

Here is a quick way to dump an image(binary) field value into a file:


DECLARE @SQL NVARCHAR(MAX)
SET @SQL = 'bcp "select [binaryfield] from [database]dbo.[table] where field = " queryout "c:\temp\output.jpg" -T -n -S ' + @@ServerName
EXEC xp_cmdshell @SQL

WHERE:
bcp => Bulk Copy Program (a utility that installs with SQL Server and can assist with large data transfers)

-T => Trusted Connection
-n => Native Type
-S => Server/Instance name

for more info on bcp type
bcp /? on command line

Detect IE10 using JavaScript

Here are possible ways to detect IE10 browser using Javascript:

Though the following aren’t perfect solution it could be a better start.

Method 1:


var ie10 = (navigator.userAgent.match(/Trident\/[6]/i));

Method 2:


var ie10 = (navigator.userAgent.match(/MSIE 10/i));

Method 3:



<!doctype>
<html>
<head>
<!--[if (gt IE 9)]><script type="text/javascript">window.ie10 = true;</script> <![endif]-->
</head>
<body>

<script type=”text/javascript”>
if(window.ie10)
document.write(‘IE 10 detected.’);
else
document.write(‘Browser is NOT IE10.’);
</script>
</body>
</html>

Extracting Text Between Words(Pattern) using Regex in JavaScript

Below are the ways to extract text between words in javascript:

Given the String “Name: John Berkins Address: LA, USA”


	var data = "Name: John Berkins Address: LA, USA";
	
	//using String.indexOf + String.substring
	var name = data.substring(data.indexOf("Name:")+6,data.indexOf("Address"));
	var addr = data.substring(data.indexOf("Address:") + 9);
	alert(name);
	alert(addr);	

	//using Regex (with the use of Non-Capturing Group(?:)
	var rname = data.match(/(?:Name:)(.+)(?:Address:)/)[1];
	var raddr = data.match(/(?:Address:)(.*)/)[1];
	alert(rname);
	alert(raddr);
	
	//Note: the regex  code above may not work if the data contains \n (newline character)
	//      this is because of the (.+) expression cannot disregards \n chars,
	//      the workaround is to change it to anoter expression or to remove the \n char before
	//		the extraction process: h
	//Example:
	//
	//data = data.replace(/\n/g,' ');
	//var rname = data.match(/(?:Name:)(.+)(?:Address:)/)[1];
	//var raddr = data.match(/(?:Address:)(.*)/)[1];
	

Generating Unique Strings in Javascript

Here is a simple way to generate a unique string in javascript.

    var ts = (new Date()).getTime().toString();
    var url = &amp;quot;ajaxHandler.php?param1=value1&amp;amp;amp;paramn=valuen&amp;amp;amp;t=&amp;quot; + ts;
    //do ajax call...

This method is very helpful for ajax developers, to overcome the problem of cached ajax requests in IE.

Update:
Here’s another way of creating unique strings

String.unique = String.guid = String.uid = String.uuid = function(){
    var idx = [], itoh = '0123456789ABCDEF'.split('');

    // Array of digits in UUID (32 digits + 4 dashes)
    for (var i = 0; i &lt; 36; i++) { idx[i] = 0xf &amp; Math.random() * 0x10; }
    // Conform to RFC 4122, section 4.4
    idx[14] = 4; // version
    idx[19] = (idx[19] &amp; 0x3) | 0x8; // high bits of clock sequence

    // Convert to hex chars
    for (var i = 0; i &lt; 36; i++) { idx[i] = itoh[idx[i]]; }

    // Insert dashes
    idx[8] = idx[13] = idx[18] = idx[23] = '-';

    return idx.join('');
}

Sample Use:

   var id=String.guid();
   va u = String.uuid();

TextArea SelectedText, SelectionStart, SelectionEnd, SelStart, SelEnd (IE and FireFox)

Simple way of getting the html textarea’s selection properties selectedText, selectionStart, selectionEnd:

Javascript:

 function getTextAreaSelection() {
   var textArea = document.getElementById('textarea1');
   if (document.selection) { //IE
       var bm = document.selection.createRange().getBookmark();
       var sel = textArea.createTextRange();
       sel.moveToBookmark(bm);
     
       var sleft = textArea.createTextRange();
       sleft.collapse(true);
       sleft.setEndPoint("EndToStart", sel);
       textArea.selectionStart = sleft.text.length
       textArea.selectionEnd = sleft.text.length + sel.text.length;
       textArea.selectedText = sel.text;  
   }
   else if (textArea.selectionStart){ //FF
      textArea.selectedText = textArea.substring(textArea.selectionStart,textArea.selectionEnd);
   }
  
   alert("Selection Start==> " + textArea.selectionStart + "\n" +
      "Selection End  ==> " + textArea.selectionEnd + "\n" +
      "Selected Text  ==> " + textArea.selectedText + "\n" +
      "TextArea Value ==> " + textArea.value);
 }

HTML:

<textarea id="textarea1"></textarea> <button onclick="getTextAreaSelection()">Get Selection Info</button>