Sie sind auf Seite 1von 4

Blog

Team

Home / Blog / HowTo: Fileupload with ASP.NET MVC

23
FEB

HowTo: Fileupload with ASP.NET MVC


Code Inside Team HowTo One comment

Search

In this HowTo Im going to give you a short invitation how to implement a fileupload with ASP.NET MVC. The Controller On the controller-side we create an ActionMethod named FileUpload:

[AcceptVerbs(HttpVerbs.Post)] public ActionResult FileUpload(HttpPostedFileBase file) { ViewData["Message"] = file.FileName + " - " + file.ContentLength.ToString(); return View("Index"); Recent Posts }

HttpPostedFileBase is an abstract basic-class and has the same characteristics like HttpPostedFile. Thats because you are able to make this with a UnitTest as well and create your own deductions from the abstract basic-class.

404-Error: Directory beats ASP.NET MVC Routing


I had a little routing problem with an ASP.NET MVC website and the solution brought me a little

With file Im able to reach several characteristics with this method and if I want to I can save the file:

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

Ah! Logic! Experience maybe some of you are familiar with this problem as well Problem: I had a pdfcrowd.com

Ah! Logic! Experience maybe some of you are familiar with this problem as well Problem: I had a controller named ReportingController and I cant open it with localhost/Reporting. Not even the Debugger worked just ...

Support us
Now the Frontend: The View In the index view I create a formulary with the HTML Helper. Important: The fileupload only works when enctype=multipart/form-data is activated!

<%using(Html.BeginForm("FileUpload", "Home", FormMethod.Post, new {enctype = "multipart/form-data"})) {%> <input type="file" name="file" id="file" /> <input type="submit" name="submit" value="Submit" /> <% } %>

Simple and fast File size: Usually you wont be able to upload files with more than 4MB. But you can change this in the web.config: maxRequestSize More Informations Scott Hanselman has written a fantastic Blogpost about this subject. It also includes how Unit-Tests could look like in such a case.

Recent comments
Mauricio Lietzke on HowTo: Time-controlled & recurrent functions in .NET & ASP.NET Karl Rakestraw on HowTo: Create SQL Table Relationships via DragnDrop

Timothy Blanca on jQuery some links Hitesh on HowTo: SQL Database web access with

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

look like in such a case. [Download Democode] If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Hitesh on HowTo: SQL Database web access with ASP.NET Dynamic Data and Entity Framework (hosted on IIS 6.0) Morton Colesar on HowTo: Time-controlled & recurrent functions in .NET & ASP.NET

0
Tw ittern

2
Like

About the author


Written by Code Inside Team
Learn more about our team.

One Response Comment on this post


Name Email Website

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Submit

Notify me of followup comments via e-mail

2012 Code-Inside

TO TOP

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Das könnte Ihnen auch gefallen