0

Captured all the required value in a Datatable.

Columns and corresponding values are added in a datatable. **Need to pass the datatable value to the mail task in ssis package.

As it is in a table format** Please suggest In mail values will be like this enter image description here

        DataTable dt = new DataTable();
        DataRow row;
        DataColumn column;
        column = new DataColumn();
        dt.Columns.Add("Count_File_Date", typeof(String));
        dt.Columns.Add("Count_File_Name", typeof(String));
        dt.Columns.Add("Count_File_LMD", typeof(String));
        dt.Columns.Add("Switch_File_Name", typeof(String));
        dt.Columns.Add("Switch_File_Date", typeof(String));
        dt.Columns.Add("Data_File_Name", typeof(String));
        dt.Columns.Add("Data_File_LMD", typeof(String));
        var directories = Directory.GetDirectories(directory);

        foreach (string subdirectory in directories)
        {
            row = dt.NewRow();
            dt.Rows.Add(row);

            if (Directory.GetFiles(subdirectory, "*.count").Length == 0)
            {
                row["Count_File_Name"] = "Count File Not Found";

            }
            else
            {
                // Getting the values of count file
                DateTime Count_L_M_D;
                string Count_File_Name;
                string[] Count_filePath1 = Directory.GetFiles(subdirectory, "*.count");
                string Content = File.ReadAllText(@Count_filePath1[0]);
                string loadedDate = DateTime.ParseExact(Content.Substring(9, 8), "yyyyMMdd",
                                CultureInfo.InvariantCulture).ToString("yyyy/MM/dd");
                DateTime Datevalue = DateTime.Parse(loadedDate);
                Count_File_Name = Path.GetFileName(Count_filePath1[0]);
                Count_L_M_D = Directory.GetLastWriteTime(Count_filePath1[0]);
                row["Count_File_Date"] = Datevalue;
                row["Count_File_Name"] = Count_File_Name;
                row["Count_File_LMD"] = Count_L_M_D;
            }

            if (Directory.GetFiles(subdirectory, "*.switch").Length == 0)
            {
                row["Switch_File_Name"] = "Switch File Not Found";

            }
            else
            {
                string[] Switch_filePath = Directory.GetFiles(subdirectory, "*.switch");
                DateTime Switch_L_M_D;
                string S_File_Name;

                S_File_Name = Path.GetFileName(Switch_filePath[0]);
                Switch_L_M_D = Directory.GetLastWriteTime(Switch_filePath[0]);

                row["Switch_File_Name"] = S_File_Name;
                row["Switch_File_Date"] = Switch_L_M_D;
            }

}

  • https://learn.microsoft.com/fr-fr/dotnet/framework/data/adonet/creating-a-datatable-from-a-query-linq-to-dataset –  Oct 16 '19 at 06:22
  • Possible duplicate of [How to convert a list into data table](https://stackoverflow.com/questions/18100783/how-to-convert-a-list-into-data-table) – Rahul Sharma Oct 16 '19 at 06:29

0 Answers0