Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

ASP.NET Fileupload

with one comment

Call me lazy cuz I am deserved it. It shocked me a bit when a production code crash on my face. As part of my job today I have to train a few admin staffs on how to operate our newly invented site www.ncdd.gov.kh/jobs it works out quiet well on my machine cuz I dev, test & teach on Mozill Firefox. But it turn out that I don’t perform enough exercise cuz I haven’t test the site with IE yeah, cuz I haven’t use IE for almost 3 years enough to forgot about it :)) anyway here is the story.

Do you know this guy System.Web.HttpPostedFile? yeah, he is my best friend when it comes to uploading file in ASP.NET. However you should know that he acted bit strange with browse in used.

Let say file1 is an instance of HttpPostedFile and if we ask him file1.FileName

Firefox return :
Hello My Friend.doc
Nice , isn’t it?

IE return :
“C:\Document & Setting ….\user_name\desktop\Hello My Friend.doc
WWOWO WHAT?! it slap me so hard to make me laugh out loud :))
Not Nice !

Anyway quick fix would be add a small detection on the file1.FileName

int lastDirSeparatorChar = file1.FileName.LastIndexOf(Path.DirectorySeparatorChar);

if (lastDirSeparatorChar > 0) {
  filename = file1.FileName.Substring(lastDirSeparatorChar + 1);
} else {
  filename = file1.FileName
}

Lesson learn – test dev. site with IE as much as I hate “IE”

Advertisements

Written by Chorn Sokun

February 1, 2008 at 5:40 pm

One Response

Subscribe to comments with RSS.

  1. Why not just using Path.GetFileName(file1.FileName)? Both IE and FF return the same result.

    Chanty Pisal

    February 21, 2008 at 1:20 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: