File Upload Inside Multi-view always shows fileupl

2019-09-05 23:13发布

I have 3 Views inside Multi-view and on second view I have FileUpload Control . I am submitting all values on third view on button_click. the problem is when i click the submit button fileuplode.HasFiles is always showing false, I know its showing false because File Upload control is not visible on Webpage. But is there any way to get the posted file details from Fileupload control which is on view 2 and submit that value on view 3..

Here Is the code of View2

 <div class="form-group">
        <label for="InputMessage">Written Note From Doctor (Approval Note)</label>
        <div class="input-group">
        <asp:FileUpload runat="server" ID="drFileUpload" placeholder="Doctor Note" class="fileupload" />
           </div>
         </div>
      <asp:Button runat="server" CssClass="btn btn-success" Text="Previous" ID="Button1" OnClick="activeView0" />
  <asp:Button runat="server" CssClass="btn btn-success" ID="txtnext2" Text="Next" OnClick="activeView2" ValidationGroup="view2" TabIndex="1" />

And on View 3 i am submitting all the values

Here is the code of Button_click on view3

`

if (drFileUpload.HasFiles)
   {
   string filename = drFileUpload.PostedFile.FileName;
   string extention = Path.GetExtension(filename);
  if (extention.ToLower() == ".jpg" | extention.ToLower().ToLower() == ".png" | extention.ToLower().ToLower() == ".jpeg")
       {
       filename = txtMobile.Text;
       int width=Convert.ToInt32(ConfigurationManager.AppSettings["ProfilePicWidth"]);
       string Destination = Convert.ToString(Server.MapPath("../Images/Members/" + filename + extention));
       CommanFunctions.ResizeImage(width, drFileUpload.PostedFile.InputStream, Destination);
      regi.ProfilePic = Destination;
       }
 else
      {
      lblError.Text = "Please Upload a valid Image";
      multiview.ActiveViewIndex = 1;
      }
   }
else
 {
   regi.ProfilePic = null;
 }

I tried to Wrap up code in Update Panel but it is not working.

1条回答
迷人小祖宗
2楼-- · 2019-09-06 00:05

i have found solution myself , as i am storing the file as HttpPostedFile on session while changing the view

   protected void activeView2(object sender, EventArgs e)
    {
        multiview.ActiveViewIndex = 2;
       // storing uploaded file into sessin view HttpPostedFile
        HttpPostedFile file = drFileUpload.PostedFile;
        Session["f1"] = file;

    }

And on Submit I am retrieving that HttpPostedFile

  // getting the image file from the stream and saving to server
                HttpPostedFile f1 = (HttpPostedFile)Session["f1"];
                int nFileLen = f1.ContentLength;
                byte[] myData = new byte[nFileLen];
                f1.InputStream.Read(myData, 0, nFileLen);

                if (f1.ContentLength != 0)
                {
                    string filename = f1.FileName;
                    string extention = Path.GetExtension(filename);
                    if (extention.ToLower() == ".jpg" | extention.ToLower().ToLower() == ".png" | extention.ToLower().ToLower() == ".jpeg")
                    {
                        filename = txtMobile.Text;
                        int width = Convert.ToInt32(ConfigurationManager.AppSettings["ProfilePicWidth"]);
                        string Destination = Convert.ToString(Server.MapPath("../Images/Members/" + filename + extention));
                        CommanFunctions.ResizeImage(width, f1.InputStream, Destination);
                        regi.ProfilePic = Destination;
                    }
                    else
                    {
                        lblError.Text = "Please Upload a valid Image";
                        multiview.ActiveViewIndex = 1;
                    }
                }

Hope This will help someone in future

查看更多
登录 后发表回答