Saturday, January 27, 2018

Interface in C# summary

An interface has the following properties:

  • An interface is like an abstract base class. Any class or struct that implements the interface must implement all its members.

  • An interface can't be instantiated directly. Its members are implemented by any class or struct that implements the interface.

  • Interfaces can contain events, indexers, methods, and properties.

  • Interfaces contain no implementation of methods.

  • A class or struct can implement multiple interfaces. A class can inherit a base class and also implement one or more interfaces.

Tuesday, May 28, 2013

Refreshing Dom Element Using JQuery

    jQuery.fn.redraw = function() {      return this.hide(0, function() {          $(this).show();      });  };    $(el).redraw();

Monday, April 29, 2013

CHM help file does not show contents in right-hand pane

Symptom: an externally-originated CHM (Compiled Help) file shows the navigation outline in the left pane, but the right pane displays the error "Navigation to the webpage was canceled".

Cause: Windows security treats ad-hoc CHM files with great suspicion and disables their content under a variety of conditions, including location of the file on a network drive. A search on Google will bring up many pages about this, including Microsoft's own knowledge base. It is unlikely to be a problem with the CHM file itself, but in the way that Windows is handling it. Even Microsoft's own CHM files can be affected.

Workarounds: One or more of the following may solve the issue. The options available will depend on which version of Windows you are using.

  1. Try copying the file from a network drive location to a local drive (e.g. to C:\Temp\).
  2. If you get a Security Warning asking if you want to open the file, un-check the option "Always ask before opening this file", if this checkbox is present.
  3. Navigate to the .chm file in Windows Explorer, right-click on the file, select Properties and click Unblock. Then click OK to save the change.
  4. If there is no "Unblock" button for the previous step, try going to the file's Properties > Advanced tab and un-check the option "File is ready for archiving". (Unverified, but a low risk change anyway).
  5. The viewer component may not be correctly registered. From the command prompt, enter regsvr32 hhctrl.ocx  and hit return.
  6. Check that the file name or folder names in the path to the file do not contain the hash character (#). Rename or move the file elsewhere if they do.

To permanently solve item #1, it is possible to edit the registry to allow network drives to be a trusted zone. A web search will bring up more detailed information.

Friday, April 12, 2013

selectionStart property (Internet Explorer)

function getInputSelection(el) {
    var start = 0, end = 0, normalizedValue, range,
        textInputRange, len, endRange;

    if (typeof el.selectionStart == "number" && typeof el.selectionEnd == "number") {
        start = el.selectionStart;
        end = el.selectionEnd;
    } else {
        range = document.selection.createRange();

        if (range && range.parentElement() == el) {
            len = el.value.length;
            normalizedValue = el.value.replace(/\r\n/g, "\n");

            // Create a working TextRange that lives only in the input
            textInputRange = el.createTextRange();
            textInputRange.moveToBookmark(range.getBookmark());

            // Check if the start and end of the selection are at the very end
            // of the input, since moveStart/moveEnd doesn't return what we want
            // in those cases
            endRange = el.createTextRange();
            endRange.collapse(false);

            if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
                start = end = len;
            } else {
                start = -textInputRange.moveStart("character", -len);
                start += normalizedValue.slice(0, start).split("\n").length - 1;

                if (textInputRange.compareEndPoints("EndToEnd", endRange) > -1) {
                    end = len;
                } else {
                    end = -textInputRange.moveEnd("character", -len);
                    end += normalizedValue.slice(0, end).split("\n").length - 1;
                }
            }
        }
    }

    return {
        start: start,
        end: end
    };
  }

Friday, January 4, 2013

Resize image proportionally javascript

function reSizeImageProportionally (imgObj,imgContainerId) {
    var container = $(imgContainerId);
   
    var imgRatio = imgObj.height / imgObj.width;
    var containerRatio = container.height() / container.width();
    var ratio = containerRatio / imgRatio;
   
    imgObj.style.height = ratio * container.height()+ "px";
    imgObj.style.width = ratio * container.width()+ "px";

    container.append(imgObj);

    return container;
};
  
Usage:
------------
var img= new Image();
img.src="http://localhost/Custom/USSI/Layers/Ticket/Legend.jpeg";
var result=reSizeImageProportionally(img,'.tl_tab_legend_panel_div'); //  Div id  or Class Name


Saturday, December 1, 2012

Count duplicates in an array

function compressArray(original) {     	var compressed = [];  	// make a copy of the input array  	var copy = original.slice(0);     	// first loop goes over every element  	for (var i = 0; i < original.length; i++) {     		var myCount = 0;	  		// loop over every element in the copy and see if it's the same  		for (var w = 0; w < copy.length; w++) {  			if (original[i] == copy[w]) {  				// increase amount of times duplicate is found  				myCount++;  				// sets item to undefined  				delete copy[w];  			}  		}     		if (myCount > 0) {  			var a = new Object();  			a.value = original[i];  			a.count = myCount;  			compressed.push(a);  		}  	}     	return compressed;  };

It should go something like this:

var testArray = new Array("dog", "dog", "cat", "buffalo", "wolf", "cat", "tiger", "cat");  var newArray = compressArray(testArray);     /*  console: [  	Object { value="dog", count=2},   	Object { value="cat", count=3},   	Object { value="buffalo", count=1},   	Object { value="wolf", count=1},   	Object { value="tiger", count=1}  ]  */

Wednesday, September 19, 2012

Console.log for IE and Chrome


<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <script type="text/javascript">
  <!--
  var alertFallback = true;
  if (typeof console === "undefined" || typeof console.log === "undefined") {
     console = {};
     if (alertFallback) {
      console.log = function(msg) {
              alert(msg);
         };
     }
   }
 //-->
  </script>
 </head>

 <body onload="console.log('Error Message')";>
  
 </body>
</html>

Saturday, September 15, 2012

Google image pop up effects in javascript

//Google image pop up effects:
// imgOld is Old image element
// imgNew is New Image element which is going to be show as it is
// Following function return left and top position of pop up dialog div in which we have to bind New image element

function getDivPos(imgOld,imgNew)
{
    var offset= imgOld.getClientRects();
   
   
    var left=offset[0].left-(imgNew.width/2-imgOld.width/2);
    var top=offset[0].top-(imgNew.height/2-imgOld.height/2);
   
    if((top + imgNew.height) > document.documentElement.clientHeight)
    {
    top= top - (top + imgNew.height - document.documentElement.clientHeight);
    }
    if((left + imgNew.width) > document.documentElement.clientWidth)
    {
      left=left - (left + imgNew.width- document.documentElement.clientWidth);
    }
   
    if(0> left)
    {
       left=document.documentElement.scrollLeft;
    }
    else
    {
       left=left+document.documentElement.scrollLeft;
    }
    if(0>top)
    {
      top=document.documentElement.scrollTop;
    }
    else
    {
      top=top+document.documentElement.scrollTop;
    }
   
       
    left=Math.round(left);
    top=Math.round(top);
   
    return ({"left":left,"top":top});
}

Friday, September 14, 2012

Resize image Proportionally using javascipt

function reSizeImage (imgToResize,expWidth,expHeight) {

          
            var originalImg = new Image();
            originalImg = imgToResize;

            var originalWidth = originalImg.width;
            var originalHeight = originalImg.height;
           
            // Return image if fit with the existing div without resize       
            if (originalWidth <= expWidth && originalHeight <= expHeight)
            {
                return imgToResize;
            }
            // Resize image
            var newImgSize = setSizePresetImage(expWidth, expHeight, originalWidth, originalHeight);
           
            var newImg = new Image();
            newImg= originalImg;
            newImg.width=newImgSize.width;
            newImg.height=newImgSize.height;
            return newImg;
       
    };
    function setSizePresetImage (expW, expH, orgW, orgH) {
        //Get radio
        var ratio = orgH / orgW;

        if (orgW >= expW && ratio <= 1) {
            orgW = expW;
            orgH = orgW * ratio;
        }
        else if (orgH >= expH) {
            orgH = expH;
            orgW = orgH / ratio;
        }
        //return new width and height
        return ({"width":orgW, "height":orgH});
    }

Monday, July 23, 2012

Xwiki introduction

XWiki is a second generation wiki that provides all the basic content management and administration features of common wikis, but with much more. XWiki takes the wiki approach to a whole new level by providing enhanced features and capabilities. With XWiki, you can build simple applications, extend the platform with custom plugins, or even build complex Web applications.

Tuesday, May 15, 2012

Read IIS SessionTimeout of Virtual Directory

class Program
    {
        static void Main(string[] args)
        {
            string urlSuffix = "";

            while(true)
            {
                Console.WriteLine("Please enter domain foldername(iis)/exit:");
                urlSuffix = Console.ReadLine();
                if (urlSuffix == "")
                {
                    urlSuffix = "ussi";
                }

                if (urlSuffix == "exit" ||urlSuffix == "Exit")
                {
                    break;
                }
                // Locals
                int iRet = 20;
                DirectoryEntry deVirDir = null;
                string vdPath = null;
                IEnumerator childs = null;
                bool gotVD = false;
                bool found = false;

                try
                {
                    //vdPath = "IIS://localhost" + System.Web.Hosting.HostingEnvironment.ApplicationID.Remove(0, 3);// Remove "/LM"
                    vdPath = "IIS://localhost/w3svc/1/root/" + urlSuffix;
                    deVirDir = new DirectoryEntry(vdPath);

                    try
                    {
                        childs = deVirDir.Children.GetEnumerator();
                        gotVD = true;
                    }
                    catch
                    {
                        // if application details are not available, check out root details
                        deVirDir = new DirectoryEntry("IIS://localhost/W3SVC");
                        childs = deVirDir.Children.GetEnumerator();
                    }

                    while (childs.MoveNext() && !found)
                    {
                        DirectoryEntry deApp = (DirectoryEntry)childs.Current;

                        if (deApp.SchemaClassName == (gotVD ? "IIsWebDirectory" : "IIsWebServer"))
                        {
                            PropertyValueCollection pvcAspSTO = deApp.Properties["AspSessionTimeout"];
                            iRet = (int)pvcAspSTO[0];// only one value
                            found = true;
                        }
                    }
                }
                catch
                {
                    iRet = 20;
                }
                Console.Write("Timeout:" + iRet.ToString()+"\n");
            } 
        }
    }

Wednesday, January 4, 2012

VS2010 error: Unable to start debugging on the web server


I run the following command in run window for installing .net 4 framework.

Now its working fine...


C:\Windows\Microsoft.NET{FrameworkFolder}\v{FrameworkNumber}\aspnet_regiis -i   

Thursday, December 22, 2011

C# Get Path of the File

  using System; using System.IO;  class Program {     static void Main()     { 	string path = "C:\\stagelist.txt";  	string extension = Path.GetExtension(path); 	string filename = Path.GetFileName(path); 	string filenameNoExtension = Path.GetFileNameWithoutExtension(path); 	string root = Path.GetPathRoot(path);  	Console.WriteLine("{0}\n{1}\n{2}\n{3}", 	    extension, 	    filename, 	    filenameNoExtension, 	    root);     } }  Output  .txt stagelist.txt stagelist C:\

Wednesday, December 21, 2011

Write into Excel in C#

Writing string data to excel file