Thursday, June 26, 2014

Regular expression to find src attribute value of img tag

This regex is very handy when we want to parse html tags and use them in our code

Regex reSrc = new Regex(@"src=(?:(['""])(?<src>(?:(?!\1).)*)\1|(?<src>[^\s>]+))", RegexOptions.IgnoreCase | RegexOptions.Singleline);

Match mSrc = reSrc.Match(htmlImageTag);

if (!string.IsNullOrEmpty(mSrc.Groups["src"].Value))
{
         string imageUrl = mSrc.Groups["src"].Value;
}



Refer:http://www.experts-exchange.com/Programming/Languages/Regular_Expressions/Q_23964786.html

Tuesday, June 10, 2014

Javascript Clear all timeouts and intervals

I came across the reuqirement in a project to use mouse over, mouse out as well as mouse click methods to call some javascript functions which basically rotate a carousel. I tried a lot to use OOTB setTimeout and clearTimeout methods but they seem to have created multiple instances of the setinterval methods. Therefore after searching a bit I came across following solution which works like a magic!

Modify OOTB methods to store and retrieve all timer ids while clearing them.

window.timeoutList = new Array();
window.intervalList = new Array();

window.oldSetTimeout = window.setTimeout;
window.oldSetInterval = window.setInterval;
window.oldClearTimeout = window.clearTimeout;
window.oldClearInterval = window.clearInterval;

window.setTimeout = function(code, delay) {
    var retval = window.oldSetTimeout(code, delay);
    window.timeoutList.push(retval);
    return retval;
};
window.clearTimeout = function(id) {
    var ind = window.timeoutList.indexOf(id);
    if(ind >= 0) {
        window.timeoutList.splice(ind, 1);
    }
    var retval = window.oldClearTimeout(id);
    return retval;
};
window.setInterval = function(code, delay) {
    var retval = window.oldSetInterval(code, delay);
    window.intervalList.push(retval);
    return retval;
};
window.clearInterval = function(id) {
    var ind = window.intervalList.indexOf(id);
    if(ind >= 0) {
        window.intervalList.splice(ind, 1);
    }
    var retval = window.oldClearInterval(id);
    return retval;
};
window.clearAllTimeouts = function() {
    for(var i in window.timeoutList) {
        window.oldClearTimeout(window.timeoutList[i]);
    }
    window.timeoutList = new Array();
};
window.clearAllIntervals = function() {
    for(var i in window.intervalList) {
        window.oldClearInterval(window.intervalList[i]);
    }
    window.intervalList = new Array();
};


Copied from http://stackoverflow.com/questions/3141064/how-to-stop-all-timeouts-and-intervals-using-javascript

Tuesday, June 3, 2014

SharePoint 2010 remove customization (Reghost) a master page or page layout file

Use the below script and change file name to the desired object


---------------------------------------------------------------------------


$s = Get-SPSite "http://<server name>/"
$w = $s.RootWeb

$ps = New-Object Microsoft.SharePoint.Publishing.PublishingSite($s)
$pls = $ps.PageLayouts
    
      
    $f = $w.GetFile("/_catalogs/masterpage/<Page Layout Name>.aspx")
Write-Host $f.CustomizedPageStatus
    if ($f.CustomizedPageStatus -eq "Customized")
    {
        Write-Host
        Write-Host "Layout page name: " -NoNewline
        Write-Host $f.Name        
        Write-Host "Status before: " -NoNewline

        Write-Host $f.CustomizedPageStatus
         
        #$f.RevertContentStream()
      
        Write-Host "Status after: " -NoNewline
        Write-Host $f.CustomizedPageStatus
    }

    
$w.Dispose()
$s.Dispose()

c# httpclient The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

 If we get this error while trying to get http reponse using HttpClient object, it could mean that certificate validation fails for the remo...