— Shang Liang

Flash Upload File with ASP.NET

Uploading file from Flash to PHP through FileReference is fairly simple.

move_uploaded_file($_FILES['Filedata']['tmp_name'], $_FILES['Filedata']['name']);

You can easily find it in any Flash upload file related tutorials or posts. But I spend almost one hour searching for a solution of how to upload file from Flash to ASP.NET.

dim myFile as HttpPostedFile=Request.Files(0)
myFile.SaveAs(Server.MapPath(myFile.FileName))

That’s it. Seems fairly simple. It’s in VB and the C# version you can get from The Algorithmist

It looks like something like this:

foreach(string fileKey in _context.Request.Files)
{
HttpPostedFile file = _context.Request.Files[fileKey];
file.SaveAs(Path.Combine(uploadDir, file.FileName));
}

12 comments
  1. Jay says: February 1, 20082:57 pm

    Thanks!! That is exactly what I was looking for.

  2. Michiel says: April 18, 20086:42 am

    This is great, it’s simple, the way it should be done!

  3. Ricky says: March 16, 200910:10 pm

    U r the man. Thanks

  4. eugene says: March 25, 20093:27 am

    thnx alot :D

  5. Arvin says: April 15, 20098:06 am

    Thank dude

  6. Burhan says: April 21, 20092:35 am

    Wow dude,
    Thanks a lot…that surely saved me a lot of time.
    Thanks again

  7. James U says: April 29, 200911:05 am

    Pls where do you place the code. in which of the page event. Thanks in advance.

  8. A. Zambrana says: October 10, 20105:44 am

    thanks a lot bro!!!!

  9. jeremie says: November 25, 20107:37 am

    Big up to you man
    it’s a great favour ti connect us at your brain

    thx you very very mush !!! ;)

  10. elone says: March 25, 20113:36 am

    hi shang liang,
    thanks for the solution! =D
    r u using Agile uploader for this post?
    seems the same.
    if that’s so.

    i would like to ask about passing the flash data from Upload.aspx to the
    vb page? (e.g.: Upload.aspx.vb)

    as in php,
    can just place in single.php with

    but in Upload.aspx
    i tried

    but it seems like i’m not able to get Request Files.
    it seems somthing related to __doPostBack() method

    may i know the right way of doing that?
    thanks in advance..

  11. elone says: March 25, 20113:39 am

    sorry i repost the lower part.

    as in php,
    can just place in single.php with
    input type=’button’ value=’upload’ onClick=”document.getElementById(‘agileUploaderSWF’).submit();”

    but in Upload.aspx
    i tried
    INPUT id=”btnUpload” class=”button” type=”button” value=”Upload” name=”btnUpload” OnClick=”document.getElementById(‘agileUploaderSWF’).submit();” runat=”server”

    but it seems like i’m not able to get Request Files.
    it seems somthing related to __doPostBack() method

    may i know the right way of doing that?
    hope to hear from you soon.
    because i’ve stuck in there for a few days..
    thanks a lot for your reply

  12. RP says: July 18, 20116:14 am

    Thanks dude, saved me!

Submit comment

For spam filtering purposes, please copy the number 3812 to the field below: