[AcceptVerbs(HttpVerbs.Post)]
public void ExportToExcel(string sheetModel, string sheetData, string password)
{
SaveFileToDB(sheetModel, sheetData);
//...
}
[AcceptVerbs(HttpVerbs.Post)]
public void SaveFileToDB(string sheetModel, string sheetData)
{
string dbConnectionStr = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\spreadsheetDB.mdf;Integrated Security=True";
SqlConnection sqlCon = new SqlConnection(dbConnectionStr);
sqlCon.Open();
//Get Spreadsheet data as Stream
Stream streamData = Spreadsheet.Save(sheetModel, sheetData, ExportFormat.XLSX, ExcelVersion.Excel2013);
Byte[] dataBytes = ((MemoryStream)streamData).ToArray();
SqlCommand sqlComm = new SqlCommand("INSERT INTO [dbo].[Table]([FileName], [FileData]) VALUES (@FileName, @FileData)", sqlCon);
sqlComm.Parameters.AddWithValue("@FileName", "Sample");
sqlComm.Parameters.AddWithValue("@FileData", dataBytes);
sqlComm.ExecuteNonQuery();
sqlCon.Close();
}
|