Click here to Skip to main content
15,847,903 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

In the page load

C#
if (ViewState["attachemnet1"] == null && flupEmailAttachment.HasFile)
      {
          ViewState["attachemnet1"] = flupEmailAttachment.FileName;
          lblAttachemnt1.Text = flupEmailAttachment.FileName;
      }
      // Next time submit and Session has values but FileUpload is Blank
      // Return the values from session to FileUpload
      else if (ViewState["attachemnet1"] != null && (!flupEmailAttachment.HasFile))
      {
          if (ViewState["attachemnet1"] != null && ViewState["attachemnet1"].ToString() != "")
          {
              lblAttachemnt1.Text = ViewState["attachemnet1"].ToString();


          }
          else
          {
              ViewState["attachemnet1"] = lblAttachemnt1.Text;
              lblAttachemnt1.Text = ViewState["attachemnet1"].ToString();


          }
      }
      // Now there could be another sictution when Session has File but user want to change the file
      // In this case we have to change the file in session object
      else if (flupEmailAttachment.HasFile)
      {
          ViewState["attachemnet1"] = flupEmailAttachment.FileName;
          lblAttachemnt1.Text = flupEmailAttachment.FileName;
      }




and

button clicked
C#
if (ViewState["attachemnet1"] != null)
              {
                  strAttachment = ViewState["strAttachment"].ToString();
                  flupEmailAttachment.PostedFile.SaveAs(Server.MapPath("~/uploads/") + strAttachment);

                  //if (!Directory.Exists(fileSavePath))
                  //    Directory.CreateDirectory(fileSavePath);

                  ////after checking or creating folder it's time to save the file
                  ////fileSavePath = fileSavePath + "//" + ViewState["attachemnet1"].ToString();
                  ////flupEmailAttachment.PostedFile.SaveAs(fileSavePath);

                  //FileStream newFile = new FileStream(fileSavePath + ViewState["attachemnet1"].ToString(), FileMode.Create);

                  //// Write data to the file
                  //byte[] Buffer = (byte[])ViewState["attachemnet1"];
                  //newFile.Write(Buffer, 0, Buffer.Length);

                  //// Close file

                  //newFile.Close();
              }


but when i debug the code file content is zero.
and file sending 0 kb when sending mail
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900