I have a program that calls a stored procedure which works well.
The result of this, gives me 10 files with the name of the different projects.
What I'm trying to do is to be able to compress those 10 files and make a single .ZIP file that contains these files and then all the 10 original .CSV files can be deleted.
How could I do this?
Here is my code:
List<string> projectName = new List<string>();
List<string> category = new List<string>();
List<string> Subcategory = new List<string>();
int count = xml.GetElementsByTagName("projectName").Count;
for (int i = 0; i < count; ++i)
{
projectName.Add(xml.GetElementsByTagName("projectName")[i].InnerText);
category.Add(xml.GetElementsByTagName("category")[i].InnerText);
Subcategory.Add(xml.GetElementsByTagName("Subcategory")[i].InnerText);
}
for (int i = 0; i < count; ++i)
{
string outCsvFile = string.Format(@"C:\temp\{0}.csv", category[i] + " " + Subcategory[i]);
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Connection = conn;
sqlCmd.CommandText = "testStoredProcedure";
sqlCmd.Parameters.AddWithValue("@ProjectTitle", projectName[i]);
sqlCmd.Parameters.AddWithValue("@Category", category[i]);
sqlCmd.Parameters.AddWithValue("@SubCategory", Subcategory[i]);
sqlCmd.Parameters.AddWithValue("@TaskType", "");
sqlCmd.Parameters.AddWithValue("@TaskStatus", "");
sqlCmd.Parameters.AddWithValue("@IsBaseLanguage", 1);
sqlCmd.Parameters.AddWithValue("@RaterDemographics", "FirtName,LastName,Email,Adress");
conn.Open();
SqlDataReader reader = sqlCmd.ExecuteReader();
using (StreamWriter file = new StreamWriter(outCsvFile))
{
List<string> items = new List<string>();
for (int j = 0; j <= 5; j++)
{
items.Add(reader.GetName(j));
}
file.WriteLine("\"" + string.Join("\",\"", items) + "\"");
while (reader.Read())
{
items = new List<string>();
for (int j = 0; j <= 5; j++)
{
items.Add(reader[j].ToString());
}
file.WriteLine("\"" + string.Join("\",\"", items) + "\"");
}
}
conn.Close();
}