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 ....
LVL 58
GaryAsked:
Who is Participating?
 
Computer101Connect With a Mentor Commented:
PAQed with points refunded (500)

Computer101
EE Admin
0
 
rdivilbissCommented:
Does IUSR_machinename have write access to the folder?
0
 
kevp75Commented:
you also made need to see if the file is read-only...

I wonder if there is a flag to do the overwrite....
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
GaryAuthor Commented:
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#
0
 
GaryAuthor Commented:
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.
0
 
GaryAuthor Commented:
Ahh solved it, wasnt disposing of
i = System.Drawing.Image.FromFile(strFilename)

:)
0
All Courses

From novice to tech pro — start learning today.