Results 1 to 3 of 3

Thread: Uploading Files in ASP .NET MVC3

  1. #1
    Unmoderated abhijit's Avatar
    Join Date
    Jun 99
    Location
    Chit Chat Forum.
    Posts
    3,117

    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 File

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

    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 04
    Location
    /dev/st0
    Posts
    1,426

    Re: Uploading Files in ASP .NET MVC3

    Don't forget about rep points if you think a post has benefited you in any way.
    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
  •