Accessing input type file at server side in asp.net

后端 未结 5 495
别跟我提以往
别跟我提以往 2021-01-03 02:57

I am using the tag to upload a file to the server. How do I access the file at the server side and store it at the server? (The fi

5条回答
  •  醉梦人生
    2021-01-03 03:32

    If you give the input-tag an id and add the runat="server" attribute then you can access it easily.
    First change your input tag:
    Then add the following to your Page_Load method:

    if (FileUpload.PostedFile != null) 
    {
      FileUpload.PostedFile.SaveAs(@"some path here");
    }
    

    This will write your file to a folder of your choice. You can access the PostedFile object if you need to determine the file type or original file name.

提交回复
热议问题