Hello I Have A Method That Converts Sql Data Reader To Yogesh.ExcelXmlWorkBook And Save It Into An Specified Folder,But I Want To Store It Directly To Database With Binary Format,Could You Please Help Me How Can I Convert It to Byte Array And Save It Directly Into Database? Thanks A Lot.
public static string ExportToXML(int reportCode, SqlDataReader sqlReader, bool hasHeader)
{
string randomName = "";
try
{
if (reportDefaultPath == "")
{
// reportDefaultPath = HttpContext.Current.Server.MapPath("~/Files/ReportResult/{0}");
reportDefaultPath = System.Configuration.ConfigurationSettings.AppSettings["PicPath"].ToString() + "\\ReportResult\\{0}";
}
ExcelXmlWorkbook book = new ExcelXmlWorkbook();
book.Properties.Author = "Raahabr";
Yogesh.ExcelXml.Worksheet sheet = book[0];
sheet.Name = "";
sheet.FreezeTopRows = 4;
// sheet.Border.LineStyle = Yogesh.ExcelXml.Borderline.Continuous;
// sheet.Border.Sides = BorderSides.Bottom;
int startCol = 3;
int currentRow = 3;
int colCount = sqlReader.FieldCount;
if (hasHeader)
{
ReportBOL rbol = new ReportBOL();
Dictionary<string, string> cNames = rbol.getColumnNames(reportCode);
for (int i = 0; i < colCount; i++)
{
string head = sqlReader.GetName(i);
string value = (cNames.ContainsKey(head)) ? cNames[head] : head;
if (value.ToString() == "")
value = head;
sheet[currentRow + i, currentRow].Value = value;
sheet[currentRow + i, currentRow].Border.LineStyle = Borderline.Continuous;
sheet[currentRow + i, currentRow].Border.Sides = BorderSides.All;
}
}
currentRow++;
if (sqlReader.HasRows)
{
while (sqlReader.Read())
{
for (int i = 0; i < colCount; i++)
{
sheet[startCol + i, currentRow].Value = sqlReader[i].ToString();
sheet[startCol + i, currentRow].Border.LineStyle = Borderline.Continuous;
sheet[startCol + i, currentRow].Border.Sides = BorderSides.All;
}
currentRow++;
}
}
randomName = getRandomName();
book.Export(string.Format(reportDefaultPath, randomName));
var tools = new Tools();
book.DeleteSheet(0);
}
catch (Exception ex)
{
// System.IO.File.WriteAllText(HttpContext.Current.Server.MapPath("~/err.txt"), randomName + ";" + reportDefaultPath + "\r\n" + ex.Message + "\r" + ex.StackTrace);
}
finally
{
sqlReader.Close();
sqlReader.Dispose();
}
return randomName;
}```