Thursday, March 27, 2014

Set control's colour pragmatically in C#

In order to set control's colour pragmatically, I used following syntax in C#

btnSearch.ForeColor = Color.FromArgb(0x444444);

Thursday, February 27, 2014

Check for string if it contains positive integer in C#

In order to check if strings is positive integer I used following check in C#

        String maxRecords;

        if (maxRecords == "" || !maxRecords.All(Char.IsDigit))
        {
               // Logic to implement when string contains no valid postive integer.
        }

Monday, February 24, 2014

Wrap text for the particular column of GridView

In order to wrap particular column of GridView of ASP.NET I used following

    protected void GridViewLog_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[7].Attributes.Add("style", "word-break:break-all;word-wrap:normal");
    }

Here column 7 of the GridView gets text wrapped.

Wednesday, February 12, 2014

Close Browser using C#

In Order to Kill (close) all Internet Explorer browser launched, I used following C# code

            Process[] localByName = Process.GetProcessesByName("iexplore");

            foreach (Process item in localByName)
            {
                try
                {
                    item.Kill();
                }
                catch
                {

                }
            }

Tuesday, February 11, 2014

CruiseControl Scheduled Trigger

In order to schedule CruiseControl build at specific time every day, I used following trigger in the project block

<triggers>
<scheduleTrigger time="22:00" buildCondition="ForceBuild" />
    </triggers>

Start and Stop IIS Website using PowerShell

In Order to stop and start website using PowerShell script I used following command

Import-Module WebAdministration

Stop-WebSite -Name 'Maintenance'

Start-Sleep -s 5

Start-WebSite -Name 'Maintenance'

Wednesday, February 05, 2014

Show stack trace in NUnit report in CruiseControl Dashboard

In order to have stack train in CruiseControl NUnit webdashboard report, I have added <xsl:value-of select="./failure/stack-trace"/> in webdashboard\xsl\nunitv2.xsl file. Here is the snippet

        <xsl:if test="@success != 'True' ">
      <tr bgcolor="#FF9900"><td colspan="3"><xsl:value-of select="./failure/message"/><br></br><br></br><xsl:value-of select="./failure/stack-trace"/></td></tr>
</xsl:if>

Monday, December 09, 2013

Using extra & with XMLPoke of nAnt

When using XMLPoke on nAnt I used extra amp; when String already contains &amp;

For example

<xmlpoke file="Menu.xml" xpath="//Item[Name[text()='ams']]//ArgumentExpression" value="https://www.myserver.com/Home.aspx?TID={session}&amp;cid={cid}&amp;Username={username}&amp;uiculture={uiculture}" />

I used following extra &amp; as shown below and XMLPoke worked.

<xmlpoke file="Menu.xml" xpath="//Item[Name[text()='ams']]//ArgumentExpression" value="https://www.myserver.com/Home.aspx?TID={session}&amp;amp;cid={cid}&amp;amp;Username={username}&amp;amp;uiculture={uiculture}" />
 

Wednesday, November 20, 2013

Get Installed .NET versions list

In order to know which .NET frameworks being installed, use following command from the Comand Promt

wmic product where "Name like 'Microsoft .Net%'" get Name, Version

Wednesday, August 07, 2013

Get Multiple Services using Single PowerShell Command

In order to get multiple services using single PowerShell command I used following

Get-Service | Where-Object {($_.name -like "FV*") -or ($_.name -like "QESE*")}

Wednesday, December 12, 2012

Clean Redis DB

In order to clean redis database, I used following commnad

redis-cli -p 1216

redis-cli> flushall

Delete all Objects (Images) from Excel Workbook

Select the workbook
Press F5
Click Special
Select Objects
Click OK
Press Delete key from Keyboard

Friday, May 11, 2012

XPATH with namespace

In order to execute XPATH on XML file with namespace, I used following syntax while using nant's xmlpoke command
 

<xmlpoke file="myfile.xml" xpath="/x:Project/x:PropertyGroup/x:ApplicationVersion" value="1234" >
<namespaces>
<namespace prefix="x" uri="http://schemas.microsoft.com/developer/msbuild/2003" />
</namespaces>
</xmlpoke>

Thursday, May 10, 2012

Display batch file output on console and write to file simultaneously

In order to see output of DOS Batch file on console as well as log to file simultaneously, I used following syntax

executeme.bat > C:\log.txt && type C:\log.txt

Thursday, October 06, 2011

Echo without carriage return or line feed

In order to remain on same line (without carriage return or line feed) using echo in DOS batch file, I used the following syntax

echo.|set /p= My text here & echo some other text

Tuesday, July 26, 2011

Install PHP and Apache on Ubuntu server

In order to install PHP and Apache on Ubuntu server, I used the following commands

sudo apt-get install apache2

sudo apt-get install php5

sudo apt-get install libapache2-mod-php5

sudo /etc/init.d/apache2 restart

Monday, July 18, 2011

List and Kill tasks from the Windows commandline

In order to get all running tasks from the windows command line I used the following command,

tasklist

In order to kill the task forcefully, I used the following command, where 7084 is the PID if the task.


taskkill /F /PID 7084

Tuesday, June 21, 2011

Bypass SSL security in C# WebClient

If you are using WebClient in C# and getting following error,
"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."

and you want to bypass the SSL certificate security, just use this code to bypass the security check, before calling client.OpenRead method

ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(
delegate
{
return true;
});

Thursday, April 28, 2011

Halt DOS batch execution on error

In order to halt DOS batch file on error, I used the following syntax

svn up
IF NOT ERRORLEVEL 1 GOTO SVNDONE
ECHO An error occurred with exit code 1 or higher while executing command 'svn up'
GOTO FINAL
:SVNDONE
ECHO SVN Update is successful.

:FINAL
echo DOS batch file execution finished.

Wednesday, March 02, 2011

Auto refresh the webpage using Meta tag

In order to refresh the web page automatically, I put following line in the HTML head tag, which refreshes the web page every 10 seconds

<META HTTP-EQUIV="Refresh" CONTENT="300;">