473,799 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C#-WEB(ASP.NET 2.0): Problem deleting an uploaded file, Help!

1 New Member
Hello, i have a problem when i try to delete a file that i recently uploaded.

To upload, i used the FileUpload, when i receive the file, i save it in a directory inside the virtual application (ASPNET account have full control on it, ).
...
try
{
//Save the image
FileUpload1.Pos tedFile.SaveAs( savepath); <---This work OK.
FileUpload1.Pos tedFile.InputSt ream.Close();

//Save the virtual path
ImageList.Add(u rlAbsolutePath) ;
Session["ImageList"] = ImageList;
btnUpload.Text = "add another image";
}
...
The problem is when i try to delete it

void btn_Click(objec t sender, EventArgs e)
{
Button btn = (Button)sender;
int index = int.Parse(btn.C ommandArgument) ;
List<string> ImageList = (List<string>)S ession["ImageList"];
string urlPath = ImageList[index];
try
{
//Delete the image entry from the list
ImageList.Remov eAt(index);
//Delete the image entry from the table
TblImages.Rows. RemoveAt(index) ;

//Get the path where is the image
string savePath = Server.MapPath( urlPath);

//Delete the image <-----Access Denied Exception
File.Delete(sav ePath);
}
catch (Exception ex)
{

}
}

I think that the problem is that IIS 5.0 is locking the file, so i can't delete it.

Thank's in advance....
Aug 17 '07 #1
2 2501
kunal pawar
297 Contributor
Hello, i have a problem when i try to delete a file that i recently uploaded.

To upload, i used the FileUpload, when i receive the file, i save it in a directory inside the virtual application (ASPNET account have full control on it, ).
...
try
{
//Save the image
FileUpload1.Pos tedFile.SaveAs( savepath); <---This work OK.
FileUpload1.Pos tedFile.InputSt ream.Close();

//Save the virtual path
ImageList.Add(u rlAbsolutePath) ;
Session["ImageList"] = ImageList;
btnUpload.Text = "add another image";
}
...
The problem is when i try to delete it

void btn_Click(objec t sender, EventArgs e)
{
Button btn = (Button)sender;
int index = int.Parse(btn.C ommandArgument) ;
List<string> ImageList = (List<string>)S ession["ImageList"];
string urlPath = ImageList[index];
try
{
//Delete the image entry from the list
ImageList.Remov eAt(index);
//Delete the image entry from the table
TblImages.Rows. RemoveAt(index) ;

//Get the path where is the image
string savePath = Server.MapPath( urlPath);

//Delete the image <-----Access Denied Exception
File.Delete(sav ePath);
}
catch (Exception ex)
{

}
}

I think that the problem is that IIS 5.0 is locking the file, so i can't delete it.

Thank's in advance....

Used Response.flush( )
before delete the file. This finish all work and then proceed to next one
Oct 23 '07 #2
Plater
7,872 Recognized Expert Expert
I would think that since you're adding the file to the imagelist, that you cannot delete it's actual file?
I know if you assign an image to a control, it won't let you delete the file, because the control has an open handle to it?
Oct 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
15916
by: smilesinblues | last post by:
Hi, I have to allow my visitors to upload image on my site. I am using the follwoing code to do that: $uploaddir = 'admin/'; $uploadfile = $uploaddir . basename($_FILES); move_uploaded_file($_FILES, $uploadfile); My problem is that I expect them to use same file name, like all of
2
4414
by: Don | last post by:
Hi all, I need to read an uploaded file into chunks, so I can examine the acculative size between chunks to determine if a maximum size is being exceeded. I'm currently using the PHP function "move_uploaded_file()" to move it in one piece. But, I'm finding some clients files are bigger than I want to allow, and with that function I don't have an opportunity to determine that until the entire file has been uploaded. Thanks for any...
2
1850
by: ketulp_baroda | last post by:
Hi I want to determine the content type of uploaded file. File was uploaded by using <input type=file>. How can I determine the content type?
2
2078
by: SoSaucily | last post by:
I am getting the 'partially uploaded file' error with uploads over about 4k-5k. $_FILE = 3. Rackin my brain on this one, any help appreciated. Php.ini - upload_max_filesize=2M - post_max_size=8M and we have the <input type="hidden" name="MAX_FILE_SIZE" value="5000000"> input tag appearing prior to <input type="file"
1
1130
by: Sobhan Vezzu | last post by:
Hi All, Using a webpage I am uploading the file onto webserver. First time it works fine. If I use the same file from second time it throws an error. Error: "The process cannot access the file "<FileName>" because it is being used by another process."
4
2420
by: riteshjain82 | last post by:
Hi, Please go through this: I am having a file (default.asp) on which i am taking many details from a user before mailing it to someone. I have also provided the user with a facility of uploading files on a server. I am uploading files from a page upload.asp which has a link on default.asp. Now my problem is that, how can i send the file name that is uploaded, in a mail along with other details that the user enters on default.asp?? In...
10
2835
by: Chris | last post by:
I have a PHP file upload feature that also gives the user the option to assign more than 1 project association to the file. The file's name, title, primary project, etc. is inserted into a document link table in a MySQL db after the file is uploaded. The secondary (and multiple) project(s) are also selected using a separate list box (there are 2 boxes - one for the primary project, and one for any/all associated projects) The selected...
8
2830
by: ctiggerf | last post by:
I was hopeing someone could help me out here. Been stumped on this one all day. This function 1. Checks uploaded files. 2. Creates two resized images from each (a full size, and a thumbnail). 3. Returns an array with a bool (false if the upload failed), and an error message.
2
5094
by: dev646 | last post by:
hi all , coming to the problem straight away... i was trying to find out how new tools,unknown for me works out in asp.net... in upload control it worked out pretty well for newbie like me. but when del. part came i'm stuck. how to do delete , for an uploaded file ? how to pop out that window (which allows you to browse and select file for deleting) ? which command for finding the path of that file ? thanks for looking into this...
0
10473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10249
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10219
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10025
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7563
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5461
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.