'After upload show uploaded file in Asp.net

I have this Asp.net code:

<asp:Panel ID="pnlCustomer" runat="server">
  <p class=".SmallCaption">
    <b>Edit report</b></p>
  <table class="DataTable" id="Bug" cellspacing="0" cellpadding="2" width="100%" border="0">

    <tr>
      <td class="CellName" width="25%">
        <asp:Label CssClass="CasualForm" id="lblUploadFile" runat="server">Save new file</asp:Label>
      </td>
      <td class="CellValue" width="25%">
        <asp:FileUpload CssClass="formdata100" ID="fuUploadedFile" runat="server" />
      </td>
      <td class="CellName" width="50%" colspan="2">&nbsp;</td>
    </tr>

    <tr>
      <td class="CellName" width="25%">
        <asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="BtnDeleteReport" style="float:left" OnClientClick="if(confirm('Do you really want to delete this report?')) {this.disabled = true;} else {return false;}" UseSubmitBehavior="false" />
      </td>
      <td class="CellName" width="25%">&nbsp;</td>
      <td class="CellName" width="47%">
        <asp:Button ID="btnDownloadFile" runat="server" Text="Get Report" onclick="btnDownloadFile_Click" />
      </td>

      <td class="CellName" width="3%">
        <asp:Button ID="btnSave" runat="server" Text="Edit" OnClientClick="if(checkFileUploadSize()) {return true;}" onclick="btnEdit_Click" CommandArgument="Edit" />
      </td>
    </tr>

  </table>
</asp:Panel>

and this is backcode C#:

protected void btnEdit_Click(object sender, EventArgs e) {
  Button btnThis = (Button) sender;
  if (btnThis.Text == "Edit") {
    Edit();
    btnThis.Text = "Save";
  } else if (btnThis.Text == "Save") {
    Save();
    //btnThis.Text = "Edit";
  }
}


private void Save() {
  ReadDataFromGUI();

  // insert/update report in DB.
  int _id = reportsHandler.Update(report);
  Response.Redirect("~/ReportsEditor.aspx?id=" + _id);
}


private void ReadDataFromGUI() {
  if (report == null)
    report = new Support_Report();
  report.id = report_id;
  report.id_entity = int.Parse(ddlEntities.SelectedValue);
  report.inactive = cbInactive.Checked;
  report.name = txtName.Text.Trim();
  report.description = txtDescription.Text.Trim();
  report.report_condition = txtReportCondition.Text.Trim();

  int _so;
  isSortOrderInteger = int.TryParse(txtSortOrder.Text.Trim(), out _so);
  if (isSortOrderInteger) {
    report.sort_order = _so;
  }

  string StrFileName = Path.GetFileName(fuUploadedFile.FileName);

  int IntFileSize = fuUploadedFile.PostedFile.ContentLength;

  if (StrFileName != null && StrFileName != "") {
    string path = Utility.Utility.GenerateTempFileName(StrFileName);
    FileInfo fi = new FileInfo(path);
    fuUploadedFile.PostedFile.SaveAs(path);

    try {
      var extension = Path.GetExtension(StrFileName).Replace(".", "");
      report.report_type = extension;
      if (extension == "mrt") {
        var xml_doc = new XmlDocument();
        xml_doc.Load(path);
        report.report_file = xml_doc.OuterXml;
      } else {
        report.report_file = Convert.ToBase64String(File.ReadAllBytes(path));
      }
    } finally {
      fi.Delete();
    }
  }
}

When I insert a file and want it to upload it looks like this: Before But when I press the "save" button then that file is deleted on the page and refreshed the page. Still, that file is in the database but I can't see it on that page. Then it looks like this after saving: After Why is this happening? How to fix that it always shows me even after the update?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source