November 17, 2009

Saving ASP.NET FileUpload files in all browsers



After a number of non-successful attempts on making the ASP.NET FileUpload dialog work in Mozilla Firefox browsers, and reading some stuff on the net, I made my own version of the FileUpload dialog, well.. actually it's just a modified version of the FileUpload from the BCL.
Anyways, it fixes the issue when FileDialog returns just the file name, instead of the full folder name , in non IE browsers , and it does so by writing the underlying stream to a file. Spares you the headache ;)

Here's the code.

P.s. to those of you who's still reading my blog, thank you and sorry for not posting in a long time.

using System;

using System.Web.UI.WebControls;

using System.IO;

namespace Animaonline

{

public class FileUploadPro : FileUpload

{

public void SaveFileMozilla(string fileName)

{

try

{

byte[] bytes = new byte[base.PostedFile.ContentLength];

PostedFile.InputStream.Read(bytes, 0, base.PostedFile.ContentLength);

using (FileStream fileWriter = new FileStream(fileName, FileMode.Create))

{

fileWriter.Write(bytes, 0, bytes.Length);

}

}

catch (Exception)

{

throw;

}

}

}

}



Back to Home

1 comment:

  1. Many thanks. Loads of tips!

    My site - MCM リュック
    my webpage - MCM バッグ

    ReplyDelete

Note: Only a member of this blog may post a comment.