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; }
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(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)