ASP.NET File Upload

前端 未结 5 1622
天命终不由人
天命终不由人 2020-11-28 14:33

I am trying to make a server page (C#, asp.net 2.0+) to save an uploaded file from another page.

Specifically, I have an HTML page with a



        
5条回答
  •  执笔经年
    2020-11-28 15:19

    I made a small test case:

    1. Uploader.aspx markup:


    2. Codebehind from Upload.aspx:

      protected void Page_Load(object sender, EventArgs e)
      {
          FileUpload fu =  PreviousPage.FindControl("fuTest") as FileUpload;
          if (fu != null)
          {
              int length = fu.PostedFile.ContentLength;
          }
      }
      

    The PostBackUrl property of the button posts it to the Upload.aspx page. There you can use the PreviousPage property of the Page class to find the control from the previous page, cast it to FileUpload, and retrieve what you want from it.

提交回复
热议问题