i have an object list and i Would like to export it in a text file. I would like that the properties name are the column header.
I 've done this
public static void Write(IList<ValidationResultAttribute> dt, string filePath)
{
int i = 0;
StreamWriter sw = null;
sw = new StreamWriter(filePath, false);
PropertyInfo[] properties = typeof(ValidationResultAttribute).GetProperties();
// write columns header
foreach (PropertyInfo property in properties)
{
sw.Write(property.Name + " ");
}
sw.WriteLine();
// write value
foreach (ValidationResultAttribute res in dt)
{
PropertyInfo[] prop = typeof(ValidationResultAttribute).GetProperties();
foreach (PropertyInfo property in prop)
{
sw.Write(property.GetValue(res, null) + " ");
}
sw.WriteLine();
}
sw.Close();
}
}
but I've this output
PresentationName SlideName ShapeName RunIndexs Attribute Rule Fail Pass
pptTest.pptx Slide1 Rectangle 3 FontSize Value 22 1 0
pptTest.pptx Slide2 TextBox 3 FontSize Between 20and 72 1 0
there is a way to format the output txt file (value under the column)?
Do following code changes to create tab delimited file. This file is easy to parse and easy to read.
sw.Write(property.Name + " ");
change this tosw.Write(property.Name + "\t");
sw.Write(property.GetValue(res, null) + " ");
change this tosw.Write(property.GetValue(res, null) + "\t");