JG Vimalan's Blog

It is all about coding!

Get the number of rows in GridView using JavaScript

The following code snippet will give an idea of accessing number of rows in a gridview from javascript.

<script type=”text/javascript”>
window.onload = function() {

var grid = document.getElementById(‘ctl00_mainContentPlaceHolder_myGridView’);
//number of rows in gridview

var rowCount = grid.rows.length – 1;    //grid rows include header
if (grid != null && rowCount <6)//grid rows include header
{


}

}
</script>

Advertisements

September 30, 2010 Posted by | JavaScript | 1 Comment

Get latest sources from tfs using .bat file

I used to get latest sources from tfs several times a day. Also, I depend on multiple projects in tfs.  So, I created a simple .bat file to get the latest sources from multiple projects in tfs by a single click. Here is the code,
ECHO STARTING. PLEASE WAIT….

CD C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC
CALL vcvarsall.bat x86
tf.exe GET ITEMSPEC /FORCE /ALL /OVERWRITE /RECURSIVE $/ProjectA
tf.exe GET ITEMSPEC /FORCE /ALL /OVERWRITE /RECURSIVE $/ProjectB
tf.exe GET ITEMSPEC /FORCE /ALL /OVERWRITE /RECURSIVE $/ProjectC/Binaries
tf.exe GET ITEMSPEC /FORCE /ALL /OVERWRITE /RECURSIVE $/ProjectD
ECHO **************************                       
ECHO       COMPLETED 
ECHO  YOUR CHECKED OUT FILES
ECHO          ARE           
ECHO    NOT OVERWRITTEN  
ECHO **************************

PAUSE

Copy the above lines of code, create a file with .bat extension and paste in it. Simple things makes your life easier.

September 30, 2010 Posted by | TFS | 5 Comments

ORA-01795: maximum number of expressions in a list is 1000

This issue occurs due to limitation in ‘IN’ clause.  The maximum number of parameters allowed is 1000. So, to resolve this issue,  use multiple IN clause with OR. Use 1000 parameters in an IN clause as shown below,

SELECT PAT_NUM, PAT_NAME, STATE FROM PATIENT WHERE  PAT_NUM IN

 (‘1′,’2’…’1000’) OR  PAT_NUM IN (‘1001’, ‘1002’,…) ORDER BY 1 ASC

this will give the expected result.

September 29, 2010 Posted by | Sql Server 2005 | 7 Comments

Automated deployment build

When you create a new build definition in tfs, you will get a .proj file created. You need to make few changes to deploy your application to the destination server automatically. Here is a sample .proj file, which deploy and make changes in the web.config automatically,

<?xml version=”1.0″ encoding=”utf-8″?>
<!– DO NOT EDIT the project element – the ToolsVersion specified here does not prevent the solutions
     and projects in the SolutionToBuild item group from targeting other versions of the .NET framework.
     –>
<Project DefaultTargets=”DesktopBuild” xmlns=”http://schemas.microsoft.com/developer/msbuild/2003” ToolsVersion=”3.5″>
 
  <!– Do not edit this –>
  <Import Project=”$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets” />
  <Import Project=”$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets”/>
 
  <ProjectExtensions>
 
    <!– Team Foundation Build Version – DO NOT CHANGE –>
    <ProjectFileVersion>2</ProjectFileVersion>
 
    <!–  DESCRIPTION
     This property is included only for backwards compatibility. The description of a build definition
     is now stored in the database. For compatibility with V1 clients, keep this property in sync with
     the value in the database.
    –>
    <Description></Description>
 
    <!–  BUILD MACHINE
     This property is included only for backwards compatibility. The default machine used for a build
     definition is now stored in the database, as the MachineName property of the definition’s
     DefaultBuildAgent. For compatibility with V1 clients, keep this property in sync with the value
     in the database.
    –>
    <BuildMachine>ABC1234</BuildMachine>
 
  </ProjectExtensions>
 
  <PropertyGroup>
 
 
   <MyProjInstallDirectory>\\ABC1122\E$\Inetpub\wwwroot\MyProjName</MyProjInstallDirectory>
 
   …………..
   …………..

  </PropertyGroup>
 
  <ItemGroup>
 
    <MyProjectApplicationFiles Include=”D:\Builds\$(BuildDefinitionId)\Binaries\Release\_PublishedWebsites\MyProj.UI\**\*.*”/>
 
   …
   …

   <SolutionToBuild Include=”$(BuildProjectFolderPath)/../../../../Prod/MyProject/MyProj.sln”>
      <Targets></Targets>
      <Properties></Properties>
    </SolutionToBuild>
 
  </ItemGroup>
 
 ….
 ….
 
  </PropertyGroup>
 
  <ItemGroup>
    <!–  ADDITIONAL REFERENCE PATH
     The list of additional reference paths to use while resolving references. For example:
    
         <AdditionalReferencePath Include=”C:\MyFolder\” />
         <AdditionalReferencePath Include=”C:\MyFolder2\” />
    –>
  </ItemGroup>
 
  <Target Name=”AfterTest”>
 
    <Message Text=”Updating Web.config” />
 
   
    <XmlUpdate
       Namespace=””
       XmlFileName=”D:\builds\$(BuildDefinitionId)\Binaries\Release\_PublishedWebsites\MyProject\MyProj.WebUI\Web.Config”
       Xpath=”//configuration/appSettings/@file
       Value=”Web.Live.config” />
 
    <XmlUpdate
       Namespace=””
       XmlFileName=”D:\builds\$(BuildDefinitionId)\Binaries\Release\_PublishedWebsites\MyProject\MyProj.WebUI\Web.Config”
       Xpath=”//configuration/system.web/compilation/@debug
       Value=”false” />
 
    <Message Text=”Copying source files to live” />
 
    <Copy SourceFiles=”@(MyProjectApplicationFiles)” OverwriteReadOnlyFiles=”true” DestinationFolder =”$(MyProjInstallDirectory)\%(RecursiveDir)” />
 
 
  </Target>
 
</Project>

September 28, 2010 Posted by | TFS | Leave a comment

Programmatically access the custom document library template

The following method finds the custom document library template in a sharepoint site.

 private Result GetSPDocLibTemplate(SPWeb spWeb, out SPListTemplate docLibTemplate)
        {
            Result result = new Result();
            result.IsSuccess = false;
            docLibTemplate = null;

            try
            {
                SPListTemplateCollection listTemplateCollection = spWeb.Site.GetCustomListTemplates(spWeb);

                foreach (SPListTemplate template in listTemplateCollection)
                {
                    if (template.Name.ToLower().Equals(“Expected Template Name”))
                    {
                        docLibTemplate = template;
                        break;
                    }
                }

                result.IsSuccess = true;
                return result;
            }
            catch(Exception error)
            {
                Log.ErrorFormat(“Error while searching for doc lib template: {0}”, error.Message);
                result.ErrorMessage = error.Message;
            }
            return result;
        }

September 27, 2010 Posted by | SharePoint | Leave a comment

Publish code coverage result via email

The following code explains the way to publish code coverage results via email.

This will happen during the contineous integration build in tfs, which executes the unit tests.

After you create a new build in tfs, you will get a .proj file. You need to add the following code in that file

to receive the code coverage results via email.
<?xml version=”1.0″ encoding=”utf-8″?>
<!– DO NOT EDIT the project element – the ToolsVersion specified here does not prevent the solutions
and projects in the SolutionToBuild item group from targeting other versions of the .NET framework.
–>
<Project DefaultTargets=”DesktopBuild” xmlns=”http://schemas.microsoft.com/developer/msbuild/2003” ToolsVersion=”3.5″>

……
……
……

<UsingTask TaskName=”PublishCodeCoverge” AssemblyFile=”$(MSBuildExtensionsPath)\MyLibrary.MSBuild.Tasks.dll” />

<ProjectExtensions>

<!– Team Foundation Build Version – DO NOT CHANGE –>
<ProjectFileVersion>2</ProjectFileVersion>


</ItemGroup>

<Message Text=”Processing code coverage results…” />
<PublishCodeCoverge  CoverageFiles=”@(CoverageFiles)”
TestResultsRootDirectory=”$(TestResultsRoot)”
OutputDirectory=”$(TestResultsRoot)”
MailTo=”vimalanjg@test.com
MailFrom=”My Project CI Build @Company.com”
BuildNumber=”$(BuildNumber)”
AssemblyPath=”$(MSBuildExtensionsPath)” />

</Target>
</Project>

September 27, 2010 Posted by | TFS | 2 Comments