Jay R Blog

.NET nuance

There's a few web apps that I've done in recent months that needed to accomodate an image upload. Every now and then, we'd get emails from Mac users claiming that they were unable to upload images. Due to being backlogged with requests, it wasn't until today that I had the timeto experiment with things enough to remedy the situation.

At any rate, here is some standard simple .NET code for use when uploading a file via http post:

Dim objFC As HttpFileCollection=Request.Files
Dim objFile As HttpPostedFile=objFC.Get(0)

objFile.SaveAs(Server.MapPath(“/wherever/whatever.jpg“))

Now this works fine when uploading from a Windows machine and some Mac's, however when I tested this it was on an OS9 Mac and this code did not in fact work very well (the file got saved, however the script request never completed; was pretty weird). It just took a little experimenting with things, and I got the code to work by doing the following:

Dim objFC As HttpFileCollection=Request.Files
Dim objFile As HttpPostedFile=objFC(0)

objFile.SaveAs(Server.MapPath(“/wherever/whatever.jpg“))

Pretty simple huh? I know it's nothing major, but figured I'd share anyway. It was driving a couple of our Mac using clients nuts. Of note is that when in situations where using a webform is an option, this works without problems on either OS. However, some of our apps are still not completely changed over from Classic ASP to .NET, thus using a webform in some circumstances is simply not an option right now.

Legacy Comments


Quintin Humphreys
2004-03-28
re: .NET nuance
Dude, thanks for this - its not such a popular subject on the net but i found you!

ill give it a shot - i have a client who cant upload.

Quintin Humphreys quintSoft www.
2004-06-02
re: .NET nuance
I just thought id add my website too!

Tim Burnett
2004-07-04
re: .NET nuance
hey I was just surfing around (looking for a jumpstart on an ASP.NET project I want to do) and ran into your blog on file uploading...

Just a quick heads up to you that uploading large files with the standard .NET file upload system will kill your server (learned this the hard way) - uploaded files are placed entire in memory during the upload process and the memory on the w3wp.exe process shoots out of sight (on IIS6, is aspnet.exe or something on IIS5).

SoftArtisans's file upload component is much better. Google on SAFileUp.

-Tim Burnett (tim (at) kingfisherconsulting.com)


KIRAN PAWAR
2005-12-29
re: .NET nuance
I AM FACING PROBLEM IN STORING LARG FILE TO DATABASE

KIRAN PAWAR
2005-12-29
re: .NET nuance
CCCCCCCCCCCC

KIRAN PAWAR
2005-12-29
re: .NET nuance
NNNNNNNB

KIRAN PAWAR
2005-12-29
re: .NET nuance
N