473,799 Members | 3,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deleting a file

210 Recognized Expert New Member
I have a .NET page built with c#. This page creates a temporary report and then creates a pdf file. Then this file is sent to users via email. After the email is sent out i have written a code to delete the temporary file. My problem is i am getting a accessed denied exception.

Exception Details: System.Unauthor izedAccessExcep tion: Access to the path 'c:\Inetpub\vho sts\***\***\*** *\10836.pdf' is denied.

here is the code that checks for the file and then performs the delete.
Expand|Select|Wrap|Line Numbers
  1.  
  2. string file = HttpContext.Current.Server.MapPath("../***/" + fileid + ".pdf");
  3.  
  4. if (File.Exists(file))
  5. {
  6.        File.Delete(file);
  7. }
  8.  
  9.  
I have set full permission on IIS for IO purpose. I am sure this error is due to permission issue. Any advice will be greatly appretiated. Thank you in advance.
Feb 3 '09 #1
7 1435
PRR
750 Recognized Expert Contributor
Look if aspnet account has permission for that particular folder... right click the folder... go to security->add->advanced ->click on find now...
click asp.net account and add and give permission to it ...this might help...
Feb 4 '09 #2
sangam56
68 New Member
Hi semomaniz, you said full access has been given to the in IIS for IO purpose. I suggest to add group Everyone in the security following the way as suggested by DeepBlue.

Hope this helps. Thanks.
Feb 4 '09 #3
semomaniz
210 Recognized Expert New Member
Thank you for the response but now i am getting a different error while trying to delete the file. The error states, the file is being used by another process. I am positive that this is because the file is being attached over the email and this is taking time to process. How do i make code to delete the file in the same click event. Is this even possible or do i have to trigger another event to delete the file?
Feb 4 '09 #4
semomaniz
210 Recognized Expert New Member
Does any body have any idea on this? I have noticed that the code is throwing and error because of the file being attached on the email before its deletion. if i do not sent the email and compile the code the pdf file is created and then deleted but since i am attaching the file after creation and trying to delete it, i am getting the error. Any idea ??

Thank you in advance
Feb 4 '09 #5
Frinavale
9,735 Recognized Expert Moderator Expert
Try giving your attaching process more time to attach the file.
Consider leaving the file in the temporary folder sit there...until the next email is sent.
Or you can leave the file sit there until the user's session times out if you're using Sessions....or you could leave it sit there until the user clicks the "ok" button that appears after the email's been sent.

I do something similar in my web application. When the user clicks a button while viewing a web report, I create a PDF version of my report and send the user a link allowing them to download the file. When the user leaves the page I clean up the file. Since the user could simply close the browser, I also attempt to clean up the temporary report in the Global.asax Session_End event to make sure that the temporary resource is removed.

-Frinny
Feb 10 '09 #6
Curtis Rutland
3,256 Recognized Expert Specialist
I don't know if you are manually writing this file or not, but if you are, make sure to .Flush() and .Close() your streams so that the process releases the file. Always close your streams.
Feb 10 '09 #7
semomaniz
210 Recognized Expert New Member
I have closed all my streams. the problem that i am encountering is that the file is being used by the email client so i am not being able to delete the file right away. I am not sure if there is a method to delete the file when file is not being used by the email client.
Feb 10 '09 #8

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

Similar topics

13
9542
by: Bob Darlington | last post by:
I have a repair and backup database routine which runs when a user closes down my application. It works fine in my development machine, but breaks on a client's at the following line: If Dir(strLDB) <> "" Then Kill (strLDB) where strLDB is the path to the ldb file. The client advises that the ldb doesn't lurk after the program closes. Any ideas?
4
14033
by: al havrilla | last post by:
hi all what does the phrase: "scalar deleting destructor" mean? i'm getting this in a debug error message using c++ 7.1 thanks Al
2
1551
by: GMK | last post by:
Dear all in my asp.net application i have a text file that is installed with my application on the server. this text file is filled with data through a web interface in my application. i need to know how could i update this text file programatically and using a web interface. what i need is not to over write the content of the text file but to delete it's content and then write a new content. id there any way to do this?
5
2694
by: George | last post by:
VB.net 2003 standard, XP windows home edition. Installed first application OK today. When I removed the application via Control Panel, there were no problems and the app folders were deleted. But when I installed the app from a CD-ROM (Release folder is in D:), when I remove the app in Control Panel these problems occur: Control Panel does not delete the application folders. When I try to delete them I get message "Cannot delete file:...
8
14032
by: shandra | last post by:
I have a file I need to delete or truncate. I tried using the KILL command in VB6. I tried using the file.delete command in VB.net. I tried manually deleting, renaming, and copying over the file... but nothing works. I keep getting the error: Cannot delete access_log: it is being used by another person or program. I tried shutting down services, I tried killing processes using the task manager, I tried rebooting, and still, I get...
2
1714
by: SiouxieQ | last post by:
Hi there, I'm using the code below to try to delete a name from a list of names in a file. Unfortunately it doesn't quite do what I want it to. Instead of looking for the name in the textbox and deleting that it is just deleting the first line of data in the file.
5
2115
by: Sandeep Singh Sekhon | last post by:
I am Developing a Web Application with ASP.NET 1.1 I have one project Folder which is virtual directory of IIS. In this directory, I have one Folder named Photos in which I used to Store Photos. On my Web Page, I have a button named delete which I used to delete photo in the folder. But when I click the button and apply the logic to delete the file, it raises an Exception that the access to the file is denied. I am using following code to...
3
2927
by: Kimera.Kimera | last post by:
I'm trying to write a program in VB.net 2003 that basically deletes all files, folders, sub-folders and sub-sub folders (etc). The program is simply for deleting the Windows/Temp folder contents, removing all the files/folders inside it. The problem i am having is that i can only delete files in the Windows/Temp folder, and i can't delete folders if they contain files, i know that you can't do this.
13
2467
by: programming | last post by:
how do i delete from a text file 1 of the following lines: jon|scott adam|smith <--delete paul|clark say i would like to delete the middle line of this txt, in member.txt what php code or logic would help me accomplish this?
1
2426
by: diyasher | last post by:
hello my code is in c#. i am using fileSystemWatcher class to watch event when file is deleted. event is fire when file is deleted, i want to stop deleting file, means when user want to delete file, file cannot be deleted. how to stop deleting file bye
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10482
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
10251
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...
0
10027
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...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
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
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.