views:

4400

answers:

6

i try Request.Files, HttpContext.Request.Files but got no luck

html form:

 <form name="" method="post" enctype="mulitipart/form-data">
     <input type="file" name="file" />
 </form>
A: 

Did you try ControllerContext.HttpContext.Request.Files?

michaeldelorenzo
tried too ..........
StoneHeart
+6  A: 

Request.Files should do it.

Scott Hanselman has a little blog post about this

   foreach (string file in Request.Files)  
    {  
       HttpPostedFile hpf = Request.Files[file] as HttpPostedFile;  
       if (hpf.ContentLength == 0)  
          continue;  
       string savedFileName = Path.Combine(  
          AppDomain.CurrentDomain.BaseDirectory,   
          Path.GetFileName(hpf.FileName));  
       hpf.SaveAs(savedFileName);  
    }
TT
+1  A: 

Most probably you have another form on the page comming from your master(s) and using the standard ASP.NET form with runat='server'. I had same issue when a form with runat='server' exists on the page.

Hope this helps, Regards

+5  A: 

In your question you have a typo. If that was in the final code, it would cause an issue. It's multipart/form-data not mulitipart/form-data.

JD Conley
A: 

Velio, I have my form tag coming from masterpage, so, what is the solution?

Mike
+6  A: 

The simplest way to handle a file in the controller is to use the HttpPostedFileBase type:

public ActionResult ImportWaypointList(HttpPostedFileBase file)
{
    // Do things with the file here

    return View();
}
Jason
it is better way then other.
4thpage