How do I get multipart POST data requests in ASP.NET C #?

How do I get multipart POST data requests in ASP.NET C #?

+2


source to share


3 answers


Markup:

<asp:FileUpload ID="FileUpload1" runat="server"  Width="175"/>
<asp:Button ID="btnUpload" runat="server" CausesValidation="false"Text="Upload" OnClick="btnUpload_Click" />
<asp:Label ID="lblMsg" Visible="false" runat="server" Text=""></asp:Label>

      



Get published file in btnUpload_Click:

HttpPostedFile File = FileUpload1.PostedFile;

int i = File.ContentLength;
byte[] Data = new byte[i + 1];

File.InputStream.Read(Data, 0, File.ContentLength);

string sFileName = System.IO.Path.GetFileName(File.FileName.Replace(" ", "_"));
string p = Server.MapPath("~/images/");

File.SaveAs(p + sFileName);

      

+3


source


The ASP.Net pipeline already handles this for you. It becomes part of the request object. It should be in the Request.Form dictionary.

Check:

http://msdn.microsoft.com/en-us/library/system.web.httprequest.form.aspx



If you are using files, you should look at HttpPostedFile to get all the files that were uploaded.

Added

Or the Request.Files collection ...

+4


source


System.Web.HttpPostedFile and System.Web.HttpFileCollection

+2


source







All Articles