Pages

Friday, November 28, 2014

How to identify the TFS process template programmatically?

TfsClientCredentials crd = new TfsClientCredentials(true);
                        Uri uri = new Uri(this.Context.ConnectionString);

                        TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(uri, crd);

                        ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));

                        ProjectInfo projectInfo = css.GetProjectFromName(this.Context.CommandParameters["ProjectName"].ToString());
                            String projectName;
                            String prjState;
                            int templateId = 0;
                            ProjectProperty[] projectProperties;


                            css.GetProjectProperties(
                                projectInfo.Uri, out projectName, out prjState, out templateId, out projectProperties);

Console.WriteLine(projectProperties[2].Value); //This will give you process template name


Refrence: Link

Tuesday, November 25, 2014

Export anything to excel

protected void LinkProcess_Click(object sender, EventArgs e)
    {
        try
        {
            Warning[] warnings;
            string[] streamids;
            string mimeType;
            string encoding;
            string extension;

            byte[] bytes = KMIReportViewer.ServerReport.Render(
               "Excel", null, out mimeType, out encoding, out extension,
               out streamids, out warnings);

            Response.ContentType = "application/ms-excel";
            Response.OutputStream.Write(bytes, 0, bytes.Length);
            Response.AddHeader("Content-Disposition", "attachment;filename=ReviewFinding.xls");

        }
        catch (Exception)
        {
        }
    }

Wednesday, November 12, 2014

SQL datediff days except saturday sunday

For workdays, Monday to Friday with a single SELECT:
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate = '2008/10/01'
SET @EndDate = '2008/10/31'


SELECT
   (DATEDIFF(dd, @StartDate, @EndDate) + 1)
  -(DATEDIFF(wk, @StartDate, @EndDate) * 2)
  -(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END)
  -(CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END)


Refrence: link