Link to home
Start Free TrialLog in
Avatar of Gary
GaryFlag for Ireland

asked on

Force file overwrite

I'm using this to write images to the server

 Request.Files[IntLoop].SaveAs(Server.MapPath(".\\hotels\\hotel_images\\" + hotelid + "_"+ (IntLoop + 1) + "." + exts));

How can I force it to overwrite the image if exists, I keep getting
The process cannot access the file ....
Avatar of rdivilbiss
rdivilbiss
Flag of United States of America image

Does IUSR_machinename have write access to the folder?
you also made need to see if the file is read-only...

I wonder if there is a flag to do the overwrite....
Avatar of Gary

ASKER

There is full access to the folder, when the image doesnt exist in the first place its fine, messing around I did a delete first if the image existed followed by a sleep before writing the new image - but this is impractical
As Kev said there must be some flag, in vb you add True to the end of the argument, but this doesnt work in c#
Avatar of Gary

ASKER

After some testing the problem seems to lie in the getimage.aspx, when I remove the call to this page the uploading works fine, but I can't see what the problem is with this file, everything is disposed etc

You can get the full script at
http://eyeonireland.com/upload.aspx.txt
http://eyeonireland.com/getimage.aspx.txt

...if you want to try testing locally.
Avatar of Gary

ASKER

Ahh solved it, wasnt disposing of
i = System.Drawing.Image.FromFile(strFilename)

:)
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial