Results 1 to 3 of 3

Thread: Uploading Files in ASP .NET MVC3

  1. #1

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,226

    Question Uploading Files in ASP .NET MVC3

    I have an existing code sample that I am trying to modify.
    My existing code in the view.

    c# Code:
    1. using(Html.BeginForm("PostPhoto", "home"))
    2.     {
    3.         <p>Your status</p>
    4.         <input type="text" name="status" id="status" value="" placeholder="Think of something" />
    5.         <input type="submit" value="Post" />
    6.     }

    I now want to add a file input to this form.
    So I did this.

    c# Code:
    1. using(Html.BeginForm("PostPhoto", "home", FormMethod.Post, new { enctype = "multipart/form-data" }))
    2.     {
    3.         <p>Your status</p>
    4.         <input type="text" name="status" id="status" value="" placeholder="Think of something" />
    5.         <input type="file" name="filepath" />
    6.         <input type="submit" value="Post" />
    7.     }

    When I load the page in the browser, it gives me an option to browse and select the file. How do I process this file in my controller?
    In my controller, I get the following message.

    Could not find file 'C:\Program Files\Common Files\Microsoft Shared\DevServer\11.0\System.Web.HttpPostedFileWrapper'.

    How do I make this work with file uploads?
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Re: Uploading Files in ASP .NET MVC3

    You can read Request.Files in your ActionResult. It's pretty easy to do.

  3. #3
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: Uploading Files in ASP .NET MVC3

    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width