SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Saving a posted file

    I have an HTML page with a form:

    Code:
    <form method="post" enctype="multipart/form-data" action="saveform.aspx">
    And the form has lots of inputs that are passed along to saveform.aspx with no problem, but I'm not sure how to grab and save the posted file:

    Code:
    <input name="Certificate" id="Certificate" type="file">
    I'm trying this but getting 0 for the count:

    Code:
    HttpFileCollection MyFileCollection = Request.Files;
        
    Response.Write("MyFileCollection.Count: " + MyFileCollection.Count); // Returns 0
        
    for (int i = 0; i < MyFileCollection.Count; i++) {
        MyFileCollection[i].SaveAs("Testing.txt");
    }
    Any ideas? I can grab all other form elements just fine using Request.Form["--whatever key--"] just fine but having a tough time with files.

    Thanks!

  2. #2
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    Response.Write("Request.Files.Count: " + Request.Files.Count);	if (Request.Files.Count > 0) {
    		HttpPostedFile file = Request.Files[0];
    		Response.Write("<br />File!");
    		file.SaveAs(Server.MapPath("certs/Testing.txt"));
    	}
    This works in all browsers but IE. For some reason Request.Files.Count returns 0. Everything is working as expected in Chrome and Firefox.

  3. #3
    SitePoint Guru Jason__C's Avatar
    Join Date
    Oct 2009
    Location
    Racoon City
    Posts
    660
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Are you using jQuery? Add: data-ajax="false" to the form.
    Chuck Norris is so tough,
    mosquitos ask for permission before they bite him

  4. #4
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jason__C View Post
    Are you using jQuery? Add: data-ajax="false" to the form.
    No. It's a simple HTML form whose action points to an ASPX file. The form data is being sent by all browsers, but for some reason when I use IE the file isn't being sent.


Bookmarks

Posting Permissions

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