I am using VS 2008,C#.net,asp.net.
I am exporting the data to excel 2003.
The exported excel is of the type .xls in IE and Chrome.
But it is not .xls type in mozilla.When open that file, it is asking which program you want to open?
What is the reason?
the program is mentioned below.
## Heading ##
private void ExportDataSetToExcel()
{
try
{
DataSet Ds = new DataSet();
DataTable DT = new DataTable();
string param = hidType.Get("Type").ToString();
string[] codes = param.Split('.');
if (codes.Length == 1)
FillGrid(Convert.ToString(param));
else
FillDrillDownGrid(codes[1], codes[0]);
if (hidType.Get("Type").ToString() == "2")
{
DT.Columns.Add("<b>Sub Group Code</b>");
DT.Columns.Add("<b>Account Sub Group</b>");
}
else if (hidType.Get("Type").ToString() == "3")
{
DT.Columns.Add("<b>Group Code</b>");
DT.Columns.Add("<b>Account Group</b>");
}
else
{
DT.Columns.Add("<b>Acc.Head Code</b>");
DT.Columns.Add("<b>Account Head</b>");
}
DT.Columns.Add("<b>Debit</b>");
DT.Columns.Add("<b>Credit</b>");
for (int j = 0; j < grdTrialBal.VisibleRowCount; j++)
{
DataRow DR;
DR = DT.NewRow();
if (hidType.Get("Type").ToString() == "2")
{
DR["<b>Sub Group Code</b>"] = grdTrialBal.GetRowValues(j, "ahdUserCode");
DR["<b>Account Sub Group</b>"] = grdTrialBal.GetRowValues(j, "ahdname");
}
else if (hidType.Get("Type").ToString() == "3")
{
DR["<b>Group Code</b>"] = grdTrialBal.GetRowValues(j, "ahdUserCode");
DR["<b>Account Group</b>"] = grdTrialBal.GetRowValues(j, "ahdname");
}
else
{
DR["<b>Acc.Head Code</b>"] = grdTrialBal.GetRowValues(j, "ahdUserCode");
DR["<b>Account Head</b>"] = grdTrialBal.GetRowValues(j, "ahdname");
}
if (Convert.ToDecimal(grdTrialBal.GetRowValues(j, "trnAhdDrAmt")) != 0)
{
DR["<b>Debit</b>"] = Convert.ToDecimal(grdTrialBal.GetRowValues(j, "trnAhdDrAmt"));
}
if (Convert.ToDecimal(grdTrialBal.GetRowValues(j, "trnAhdCrAmt")) != 0)
{
DR["<b>Credit</b>"] = Convert.ToDecimal(grdTrialBal.GetRowValues(j, "trnAhdCrAmt"));
}
CrAmount = CrAmount + Convert.ToDecimal(grdTrialBal.GetRowValues(j, "trnAhdCrAmt"));
DrAmount = DrAmount + Convert.ToDecimal(grdTrialBal.GetRowValues(j, "trnAhdDrAmt"));
DT.Rows.Add(DR);
}
DataRow Dr1;
Dr1 = DT.NewRow();
if (hidType.Get("Type").ToString() == "2")
{
Dr1["<b>Sub Group Code</b>"] = "";
Dr1["<b>Account Sub Group</b>"] = "<b>Total</b>";
}
else if (hidType.Get("Type").ToString() == "3")
{
Dr1["<b>Group Code</b>"] = "";
Dr1["<b>Account Group</b>"] = "<b>Total</b>";
}
else
{
Dr1["<b>Acc.Head Code</b>"] = "";
Dr1["<b>Account Head</b>"] = "<b>Total</b>";
}
Dr1["<b>Debit</b>"] = "<b>" + DrAmount.ToString("#0.#0") + "</b>";
Dr1["<b>Credit</b>"] = "<b>" + CrAmount.ToString("#0.#0") + "</b>";
DT.Rows.Add(Dr1);
DataGrid dg = new DataGrid();
dg.DataSource = DT;
dg.DataBind();
String strFileName = "Trial Balance Account Group Wise.xls";
if (hidType.Get("Type").ToString() == "2")
{
strFileName = "Trial Balance Account Sub Group Wise.xls";
}
else if (hidType.Get("Type").ToString() == "3")
{
strFileName = "Trial Balance Account Group Wise.xls";
}
else
{
strFileName = "Trial Balance Account Head Wise.xls";
}
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);
Response.ContentType = "application/excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
CommonFunctions cf = new CommonFunctions();
String[] aTo = mskToDate1.Text.Split(new[] { '/', '-' });
String dTo;
dTo = aTo[0] + "/" + cf.getMonthName(Convert.ToInt32(aTo[1])) + "/" + aTo[2];
if (hidType.Get("Type").ToString() == "2")
{
htw.WriteLine("<b><u><font size='5'>" + "Trial Balance - Account Sub Group Wise - As on :" + dTo + " </font></u></b>");
}
else if (hidType.Get("Type").ToString() == "3")
{
htw.WriteLine("<b><u><font size='5'>" + "Trial Balance - Account Group Wise - As on :" + dTo + " </font></u></b>");
}
else
{
htw.WriteLine("<b><u><font size='5'>" + "Trial Balance - Account Head Wise - As on : " + dTo + " </font></u></b>");
}
dg.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
dg = null;
dg.Dispose();
}
catch (Exception ex)
{
}
}
set filename in double quotes
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + strFileName+ "\"");
Related
I am trying to generate excel with following code
public void GenerateExcel(string reportName, DataTable dt)
{
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.Buffer = true;
Response.ContentType = "application/ms-excel";
Response.Write(#"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">");
Response.AddHeader("Content-Disposition", "attachment;filename= " + reportName + ".xls");
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
StringWriter ws = new StringWriter();
ws.Write("<font style='font-size:10.0pt; font-family:Calibri;'>");
// ws.Write("<BR><BR><BR>");
//sets the table border, cell spacing, border color, font of the text, background, foreground, font height
ws.Write("<Table border='1' bgColor='#ffffff' " +
"borderColor='#000000' cellSpacing='0' cellPadding='0' " +
"style='font-size:10.0pt; font-family:Calibri; background:white;'>");
string strBoldCell = "<TD bgColor='#c9c7c3' style=\"font-weight: bold\">{0}</TD>";
string strRedCell = "<TD style=\"background-color:#ff4d4d\">{0}</TD>";
string strCell = "<TD>{0}</TD>";
string strColSpan = "<TD colspan={0} style=\"font-weight: bold\">{1}</TD>";
int r;
int c;
if (dt.Rows.Count > 0)
{
try
{
ws.Write("<TR>");
for (c = 0; c < dt.Columns.Count; c++)
{
ws.Write(string.Format(strBoldCell, dt.Columns[c].ColumnName).Replace("_", ""));
}
ws.Write("</TR>");
ws.Write("\n");
for (r = 0; r < dt.Rows.Count; r++)
{
ws.Write("<TR>");
for (c = 0; c < dt.Columns.Count; c++)
{
if (string.IsNullOrEmpty(dt.Rows[r][dt.Columns[c].ColumnName].ToString()) == false)
{
if (dt.Rows[r]["Comment"].ToString() != null && dt.Rows[r]["Comment"].ToString() != "")
{
ws.Write(string.Format(strRedCell, dt.Rows[r][dt.Columns[c].ColumnName].ToString().Replace('_', ' ')));
}
else
{
ws.Write(string.Format(strCell, dt.Rows[r][dt.Columns[c].ColumnName].ToString().Replace('_', ' ')));
}
}
else
{
if (dt.Rows[r]["Comment"].ToString() != null && dt.Rows[r]["Comment"].ToString() != "")
{
ws.Write(string.Format(strRedCell, " "));
}
else
{
ws.Write(string.Format(strCell, " "));
}
}
}
ws.Write("</TR>");
ws.Write("\n");
}
}
catch (Exception ex)
{
throw ex;
}
}
else
{
ws.Write("<Tr>");
ws.Write(string.Format(strColSpan, 10, "No records found"));
ws.Write("</Tr>");
}
ws.Write("</Table>");
ws.Write("</Font>");
Response.Write(ws.ToString());
Response.Flush();
Response.End();
}
by calling above method in main method as follows
if (Cnt != 0)
{
TempData["Error"] = "There were issues with the Excel Import: Total Records: " + result.Rows.Count+" Error Row Count: "+Cnt;
}
else
{
TempData["Error"] = "No error found in given excel: Total Records: " + result.Rows.Count;
}
GenerateExcel("OutputFile" + DateTime.Now.ToString("MMddyyyyhhmmss"), result);
return View();
also trying to pass Tempdata to view but the problem is excel is generating successfully but tempdata does not showing anything in view.
if i comment the code of calling GenerateExcel method tempdata is perfectly showing on view..why this is happening?
Please Try moving calling function before setting tempdata like:
GenerateExcel("OutputFile" + DateTime.Now.ToString("MMddyyyyhhmmss"), result);
if (Cnt != 0)
{
TempData["Error"] = "There were issues with the Excel Import: Total Records: " + result.Rows.Count+" Error Row Count: "+Cnt;
}
else
{
TempData["Error"] = "No error found in given excel: Total Records: " + result.Rows.Count;
}
return View();
Am tryinng to read PDf and inside PDF controls. my pdf is generated by adobe pdf library. getting null acro fields.but my form have 4 check boxes. 4 check boxed i can use to check or uncheck . i want checkbox is checked or not.
i used itextsharp to read pdf but, it is not finding controls.
private static string GetFormFieldNamesWithValues(PdfReader pdfReader)
{
return string.Join("\r\n", pdfReader.AcroFields.Fields
.Select(x => x.Key + "=" +
pdfReader.AcroFields.GetField(x.Key) + "=" + pdfReader.AcroFields.GetFieldType(x.Key)).ToArray());
}
static void Main(string[] args)
{
DataTable filedDetails;
DataRow dr;
string cName="";
string cType = "";
string cValue = "";
int txtCount = 0;
int btnCount = 0;
int chkBoxCount = 0;
int rdButtonCount = 0;
int dropDownCount = 0;
var fileName = "C:\\PreScreenings\\ViewPDF Cien.pdf";// PDFFileName.Get(context);
//var fileName = #"C:\Users\465sanv\Downloads\Read-PDF-Controls-master\ReadPDFControl\Input\David1990.pdf";
var fields = GetFormFieldNamesWithValues(new PdfReader(fileName));
string[] splitRows = fields.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
filedDetails = new DataTable("PDF Table");
filedDetails.Columns.AddRange(new[] { new DataColumn("Control Name"), new DataColumn("Control Type"), new DataColumn("Control Value") });
foreach (string row in splitRows)
{
dr = filedDetails.NewRow();
string[] str = row.Split("=".ToCharArray(), StringSplitOptions.None);
cName = str[0].ToString();
cValue = str[1].ToString();
if (str[2].ToString() == "1")
{
btnCount++;
cType = "Button" + btnCount.ToString();
}
else if (str[2].ToString() == "2")
{
chkBoxCount++;
cType = "Check Box" + chkBoxCount.ToString();
}
else if (str[2].ToString() == "3")
{
rdButtonCount++;
cType = "Radio Button" + rdButtonCount.ToString();
}
else if (str[2].ToString() == "4")
{
txtCount++;
cType = "Text Field" + txtCount.ToString();
}
else if (str[2].ToString() == "6")
{
dropDownCount++;
cType = "Drop Down" + dropDownCount.ToString();
}
dr[0] = cName;
dr[1] = cType;
dr[2] = cValue;
filedDetails.Rows.Add(dr);
}
}
I'm working on a C# asp.net project and can't seem to get the "exporting to a .txt file from a grid view" to work.
protected void ExportGridToText() {
BindGridView();
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
StringBuilder Rowbind = new StringBuilder();
Response.ContentType = "application/text";
Response.AddHeader("Content-Disposition", "attachment;filename=GlogData.txt");
Response.ContentEncoding = System.Text.Encoding.Unicode;
Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
Response.Cache.SetCacheability(HttpCacheability.NoCache);
gvLog.DataBind();
for (int i = 2; i < gvLog.Columns.Count; i++)
{
Rowbind.Append("\"" + gvLog.Columns[i].HeaderText + "\"" + ',');
}
Rowbind.Append("\n");
for (int j = 0; j < gvLog.Rows.Count; j++)
{
for (int k = 0; k < gvLog.Columns.Count; k++)
{
Rowbind.Append("\"" + gvLog.Rows[j].Cells[k].Text + "\"" + ',');
Rowbind.Replace("<", "<");
Rowbind.Replace(">", ">");
}
Rowbind.Append("\n");
}
gvLog.AllowPaging = false;
Response.Output.Write(Rowbind.ToString());
Response.Flush();
Response.End();
}
Evrytime I run the code I get a error message:
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed
Why is it giving me this error?
How do I fix it?
Is it possible to get the data from the source... This is under the get Button that populates the GridView:
protected void GetLogBtn_Click(object sender, EventArgs e)
{
string sBeginDate = BeginDate.Text;
string sEndDate = EndDate.Text;
JObject vResultJson = new JObject();
FKWebCmdTrans cmdTrans = new FKWebCmdTrans();
DateTime dtBegin, dtEnd;
if (sBeginDate.Length > 0)
{
try
{
dtBegin = Convert.ToDateTime(sBeginDate);
sBeginDate = FKWebTools.GetFKTimeString14(dtBegin);
vResultJson.Add("begin_time", sBeginDate);
}
catch
{
BeginDate.Text = "";
}
}
if (sEndDate.Length > 0)
{
try
{
dtEnd = Convert.ToDateTime(sEndDate);
sEndDate = FKWebTools.GetFKTimeString14(dtEnd);
vResultJson.Add("end_time", sEndDate);
}
catch
{
EndDate.Text = "";
}
}
try
{
string sFinal = vResultJson.ToString(Formatting.None);
byte[] strParam = new byte[0];
cmdTrans.CreateBSCommBufferFromString(sFinal, out strParam);
mTransIdTxt.Text = FKWebTools.MakeCmd(msqlConn, "GET_LOG_DATA", mDevId, strParam);
Session["operation"] = GET_LOG_DATA;
GetLogBtn.Enabled = false;
ClearBtn.Enabled = false;
Timer.Enabled = true;
}
catch (Exception ex)
{
StatusTxt.Text = "Fail! Get Log Data! " + ex.ToString();
}
}
This is under the BindGridView:
private void BindGridView()
{
try
{
string mTransid = mTransIdTxt.Text;
string strSelectCmd = "SELECT COUNT(*) FROM tbl_fkcmd_trans_cmd_result_log_data where trans_id = '" + mTransid + "'";
SqlCommand sqlCmd = new SqlCommand(strSelectCmd, msqlConn);
SqlDataReader sqlReader = sqlCmd.ExecuteReader();
if (sqlReader.HasRows)
{
if (sqlReader.Read())
nCount = sqlReader.GetInt32(0);
}
sqlReader.Close();
sqlCmd.Dispose();
{
DataSet dsLog = new DataSet();
strSelectCmd = "SELECT * FROM tbl_fkcmd_trans_cmd_result_log_data where trans_id = '" + mTransid + "'";
SqlDataAdapter da = new SqlDataAdapter(strSelectCmd, msqlConn);
// conn.Open();
da.Fill(dsLog, "tbl_fkcmd_trans_cmd_result_log_data");
DataView dvLog = dsLog.Tables["tbl_fkcmd_trans_cmd_result_log_data"].DefaultView;
gvLog.DataSource = dvLog;
gvLog.DataBind();
StatusTxt.Text = " Total Count : " + Convert.ToString(nCount) + " Current Time :" + DateTime.Now.ToString("HH:mm:ss tt");
}
}
catch (Exception ex)
{
StatusTxt.Text = ex.ToString();
}
}
I hope this helps
Thanks in advance
Following Code is For Excel Mainly...but its successfully converting gridview to .txt file just need a little workaround..
public void ExportToExcel(System.Web.UI.WebControls.GridView controlname, string sheetname)
{
HttpContext context = HttpContext.Current;
context.Response.ClearContent();
context.Response.Buffer = true;
context.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", sheetname + ".txt"));
context.Response.ContentType = "application/text";
// context.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", sheetname + ".xls"));
// context.Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
//Change the Header Row back to white color
controlname.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < controlname.HeaderRow.Cells.Count; i++)
{
controlname.HeaderRow.Cells[i].Style.Add("background-color", "#507CD1");
}
int j = 1;
//This loop is used to apply stlye to cells based on particular row
foreach (GridViewRow gvrow in controlname.Rows)
{
gvrow.BackColor = Color.White;
if (j <= controlname.Rows.Count)
{
if (j % 2 != 0)
{
for (int k = 0; k < gvrow.Cells.Count; k++)
{
gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
}
}
}
j++;
}
controlname.RenderControl(htw);
context.Response.Write(sw.ToString());
context.Response.End();
}
I have a problem. I'm creating a CSV in runtime, then giving the user the ability to save it or open it, but it does not do anything to me, what am I doing wrong? Can someone help me?
public void WriteToCSV(List<mifid2_vpc_monitored_detail_view> list, string filename)
{
string attachment = "attachment; filename=" + filename;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType = "text/csv";
HttpContext.Current.Response.AddHeader("Pragma", "public");
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
WriteHeader();
StringBuilder csv = new StringBuilder();
string _uti, _counterparty;
DateTime _maturity, _date;
decimal _volume;
var newLine = "";
for (int i = 0; i < list.Count; i++)
{
if (list[i].uti_cd == null) _uti = "-"; else _uti = list[i].uti_cd;
if (list[i].namecounterparty == null) _counterparty = "-"; else _counterparty = list[i].namecounterparty;
if (list[i].maturity == null) _maturity = DateTime.MinValue.Date; else _maturity = list[i].maturity;
if (list[i].contract_volume == 0) _volume = 0; else _volume = list[i].contract_volume;
if (list[i].evaluation_date == null) _date = DateTime.MinValue.Date; else _date = list[i].evaluation_date;
newLine = string.Format("{0},{1},{2},{3},{4}", _uti, _counterparty, _maturity, _volume, _date);
csv.AppendLine(newLine);
}
HttpContext.Current.Response.Write(csv.ToString());
HttpContext.Current.Response.End();
}
private void WriteHeader()
{
string columnNames = "UTI code, Counterparty, Maturity, Volume, Evaluation Date";
HttpContext.Current.Response.Write(columnNames);
HttpContext.Current.Response.Write(Environment.NewLine);
}
Code works fine for me. But browser downloads file without extension.
Does filename contains file extension?
If not, try this
string attachment = "attachment; filename=" + filename + ".csv";
I still do not understand where the problem may be, I tried different solutions, then I found an example on the web that works through a demo, but that once I implement it, it does not work, it could be that I work with sharepoint 2013 and that the button that refers to the export is in a webpart?
Code:
HttpResponse Response = HttpContext.Current.Response;
string csv = string.Empty;
csv += "UTI code, Counterparty, Maturity, Volume, Evaluation Date";
csv += "\r\n";
string _uti, _counterparty;
DateTime _maturity, _date;
decimal _volume;
for (int i = 0; i < list.Count; i++)
{
if (list[i].uti_cd == null) _uti = "-"; else _uti = list[i].uti_cd;
if (list[i].namecounterparty == null) _counterparty = "-"; else _counterparty = list[i].namecounterparty;
if (list[i].maturity == null) _maturity = DateTime.MinValue.Date; else _maturity = list[i].maturity;
if (list[i].contract_volume == 0) _volume = 0; else _volume = list[i].contract_volume;
if (list[i].evaluation_date == null) _date = DateTime.MinValue.Date; else _date = list[i].evaluation_date;
csv += _uti + ",";
csv += _counterparty + ",";
csv += _maturity + ",";
csv += _volume + ",";
csv += _date;
csv += "\r\n";
}
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=SqlExport.csv");
Response.Charset = "";
Response.ContentType = "application/text";
Response.Output.Write(csv);
Response.Flush();
Response.End();
This should help:
public void WriteToCSV(List<mifid2_vpc_monitored_detail_view> list, string filename)
{
string attachment = "attachment; filename=" + filename;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType = "text/csv";
HttpContext.Current.Response.AddHeader("Pragma", "public");
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
WriteHeader();
StringBuilder csv = new StringBuilder();
string _uti, _counterparty;
DateTime _maturity, _date;
decimal _volume;
var newLine = "";
for (int i = 0; i < list.Count; i++)
{
if (list[i].uti_cd == null) _uti = "-"; else _uti = list[i].uti_cd;
if (list[i].namecounterparty == null) _counterparty = "-"; else _counterparty = list[i].namecounterparty;
if (list[i].maturity == null) _maturity = DateTime.MinValue.Date; else _maturity = list[i].maturity;
if (list[i].contract_volume == 0) _volume = 0; else _volume = list[i].contract_volume;
if (list[i].evaluation_date == null) _date = DateTime.MinValue.Date; else _date = list[i].evaluation_date;
newLine = string.Format("{0},{1},{2},{3},{4}", _uti, _counterparty, _maturity, _volume, _date);
csv.AppendLine(newLine);
}
MemoryStream mstream = new MemoryStream();
StreamWriter sw = new StreamWriter(mstream);
sw.Write(csv);
sw.Flush();
sw.Close();
byte[] byteArray = mstream.ToArray();
mstream.Flush();
mstream.Close();
HttpContext.Current.Response.BinaryWrite(byteArray);
HttpContext.Current.Response.End();
}
I need help here.I don't know how to tell to labels from different stringBuilder to go on different .doc files.In my if() statements in need to tell to write labels from first stringBuilder and in another if() statement should write labels from another stingBuilder in another .doc file. Below is my code:
StringBuilder strBody = new StringBuilder();
StringBuilder strBody1 = new StringBuilder();
strBody.Append(#"<html " +
"xmlns:o='urn:schemas-microsoft-com:office:office' " +
"xmlns:w='urn:schemas-microsoft-com:office:word'" +
"xmlns='http://www.w3.org/TR/REC-html40'>" +
"<head><title>Time</title>");
strBody1.Append(#"<html " +
"xmlns:o='urn:schemas-microsoft-com:office:office' " +
"xmlns:w='urn:schemas-microsoft-com:office:word'" +
"xmlns='http://www.w3.org/TR/REC-html40'>" +
"<head><title>Time</title>");
strBody.Append("<body lang=EN-US style='tab-interval:.5in'>" +
"<p style='color:red; font-size:13px'>" +
Label47.Text +"<br/>" +
Label45.Text +"X "+
Label48.Text +" " +
Label54.Text +"</p>" +
"</div></body></html>").Append(strBody1.ToString());
strBody1.Append("<body lang=EN-US style='tab-interval:.5in'>" +
"<p style='color:red; font-size:13px'>" +
Label12.Text +"<br/>" +
Label11.Text +"X "+
Label13.Text +" " +
Label17.Text +"</p>" +
"</div></body></html>");
if (Session["one"] != null && Session["two"] != null && Session["three"] != null)
{
{
string path = #"c:\Backup\kitchen.doc";
string path2 = #"c:\Backup\bar.doc";
if (!File.Exists(path) && !File.Exists(path2))
{
using (StreamWriter sw = File.CreateText(path))
{
using (StreamWriter sw2 = File.CreateText(path2))
{
if (Label53.Text == "4")
{
sw.WriteLine(strBody);
}
else if (Label53.Text == "1")
{
sw2.WriteLine(strBody);
if (Label44.Text == "4")
{
sw.WriteLine(strBody1);
}
else if (Label44.Text == "1")
{
sw2.WriteLine(strBody1);
}
}
I think there is a missing closing } in your if conditions. The
else if (Label53.Text == "1")
did not have a closing }
Updated if conditions
if (Label53.Text == "4")
{
sw.WriteLine(strBody);
}
else if (Label53.Text == "1")
{
sw2.WriteLine(strBody);
}
if (Label44.Text == "4")
{
sw.WriteLine(strBody1);
}
else if (Label44.Text == "1")
{
sw2.WriteLine(strBody1);
}