473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

[VB.net] - Access Denied Exception Error

79
Hello,

I have a program which deletes files from cache

for exampe:-
Temporary Internet Cache
History Cache
Cookie Cache
and finally TEMP cache

while i (my program) was deleting the TEMP cache an exception error occured saying that access is denied :(

Why is this error occuring - i manually browsed to the TEMP folder and tried to delete that file and it gave me an access denied error too :(
could some one provide a working solution for this

i'm using VB.net += VB2005

Thanks in Advance
Regards
Sep 19 '08 #1
5 2754
balabaster
797 Expert 512MB
If the system is preventing you deleting the file, there will be no workaround with .NET. The o/s is preventing deletion of the file and likely with good reason. The likely cause is that an application is currently using that file. You'll probably say "I don't have any applications open", but I'll bet if you open task manager you'll probably find a bunch of applications in the list that are resident in memory that don't show up on your toolbar. One of these has either got the file locked - or a previous application didn't unlock the file before it closed down. If no application is currently using the file, then eventually the o/s will unlock it - otherwise, the only alternative is to reboot the computer you're running the code on, at which point the file will be unlocked and you can delete it either through Windows Explorer or through your .NET code...

Hope that helps,

Ben
Sep 19 '08 #2
zubair1
79
Hi,

Thanks Ben :)

Actually i wasn't going to say that "Theres no application =P" i had a few like Internet Explorer, MSN, FireFox, 3D StudioMAX :( i'll try and close them all and see if it helps any.. i assume it wont for now..

anyways, Mr.Expert :D how do i delete the file :( have you used the software Crap Cleaner / cCleaner ? it cleans these files - i'm not sure how :( but i am pretty sure it does it after a reboot (maybe).

You are also saying the same to reboot and delete but sir could you tell me how i can accomplish this by demostrating a small chunk of code or something i am very new to VB.net :(

Thanks in Advance
Regards
Sep 19 '08 #3
balabaster
797 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. Try
  2.   Dim oSearchPath = System.Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)
  3.   Dim oFolder = New System.IO.DirectoryInfo(oSearchPath)
  4.   For Each oFile As System.IO.FileInfo In oFolder.GetFiles()
  5.     oFile.Delete()
  6.   Next
  7. Catch ex As Exception
  8.   MessageBox.Show("Unable to delete file. " & ex.Message)
  9. End Try
Of course, if the file is locked...you will get the message box telling you that the file couldn't be deleted, which could get annoying pretty quickly. Better to write the file name and the reason the file couldn't be deleted to a log that you can review afterwards...

If you want to have these deleted on reboot, you have to set up a sentinel that can be loaded as a service as windows starts so that it beats all other applications to the folders. You obviously want this to run as the o/s boots rather than after you've logged in. So you'd write some kind of service to run once as the system is booting up. Windows services are relatively straight forward, although I will admit I've never written one for this purpose so I'm not sure exactly how difficult it will be.

My first thought is that your process for deleting the files would save a log of files to delete at reboot (those which it couldn't delete successfully), when the process is complete, if the log holds any file paths, then it flags the user to tell them that some files will need to be removed after the next restart. The Windows Service you wrote would then be set to autostart which would allow it to start automatically at the next reboot. It could then read the log file and delete each file that occurred before which setting itself back to manual and stopping.
Sep 19 '08 #4
jg007
283 100+
to find out why you cannot delete the file download the sysinternals program ' handle.exe ' when ran against a file it will show you which program is using the file.

to delete on reboot you will need to find some way of making your program delete the files BEFORE this program starts .

in general there are a fairly small amount of files locked and most of them are only used until you next restart anyway so I would be inclined to sugest that you just implement some error handling to ignore any locked files and just delete those which you can as it would be much easier.
Sep 19 '08 #5
zubair1
79
Expand|Select|Wrap|Line Numbers
  1. Try
  2.   Dim oSearchPath = System.Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)
  3.   Dim oFolder = New System.IO.DirectoryInfo(oSearchPath)
  4.   For Each oFile As System.IO.FileInfo In oFolder.GetFiles()
  5.     oFile.Delete()
  6.   Next
  7. Catch ex As Exception
  8.   MessageBox.Show("Unable to delete file. " & ex.Message)
  9. End Try
Of course, if the file is locked...you will get the message box telling you that the file couldn't be deleted, which could get annoying pretty quickly. Better to write the file name and the reason the file couldn't be deleted to a log that you can review afterwards...

If you want to have these deleted on reboot, you have to set up a sentinel that can be loaded as a service as windows starts so that it beats all other applications to the folders. You obviously want this to run as the o/s boots rather than after you've logged in. So you'd write some kind of service to run once as the system is booting up. Windows services are relatively straight forward, although I will admit I've never written one for this purpose so I'm not sure exactly how difficult it will be.

My first thought is that your process for deleting the files would save a log of files to delete at reboot (those which it couldn't delete successfully), when the process is complete, if the log holds any file paths, then it flags the user to tell them that some files will need to be removed after the next restart. The Windows Service you wrote would then be set to autostart which would allow it to start automatically at the next reboot. It could then read the log file and delete each file that occurred before which setting itself back to manual and stopping.

Thanks for the prompt response :)

I tried running the code -

i copied and pasted the code into my form load event
and when it loaded nothing happened - no errors no thing :o

i also checked the cache and its still there too :o

Really appreciate your Efforts
:)
Sep 19 '08 #6

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

Similar topics

1
by: AlexB | last post by:
The ASP.NET account needs access to the following directory: C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 \Temporary ASP.NET Files Locate the folder in Windows Explorer, right-click on the...
4
by: Fabian von Romberg | last post by:
Hi, I have installed Sql Reporting Services on 2 machines, one is WIN 2000 PRO and the other one is WIN 2000 ADV. SERVER. When I try to access a report using the webbrowser, I get the following...
2
by: Brent Burkart | last post by:
I am trying to send an email using SMTP server through IIS. I am recieving the following error. Access is denied. Description: An unhandled exception occurred during the execution of the...
9
by: Marc Miller | last post by:
Hi all, I have 2 dev. machines, the 1st is Win 2000 with .NET 7.0 and the 2nd is XP Pro with .NET 2003. My Web Server is Win 2000 Server with IIS 5.0. I can create a new project on my test...
0
by: ASP.Confused | last post by:
The old message looked a little stale, so I am re-posting it here. Anybody have any ideas of what I could do?!? The previous responses to this question are below. If you want to look at the...
4
by: Bruce | last post by:
I am developing an ASP.NET web service application. It works fine on my WinXP Prof development machine. But when I send it to a Windows Server 2003 system I get the following error (attached...
16
by: Nathan Sokalski | last post by:
I have Visual Studio .NET and SQL Server Desktop Engine on my computer. I have created an empty database using Visual Studio .NET's Server Explorer. However, I am having trouble connecting to the...
0
by: Doug | last post by:
I had a working NT2000 member server running IIS Ver.5.0 with a published ASP.NET application for the past couple years. I felt the need to join the server to my AD Domain and load AD on the...
23
by: deathtospam | last post by:
A day or two ago, I wrote a quick ASPX page with a CS codebehind using Visual Studio .NET 2005 -- it worked, I saved it and closed the project. Today, I came back to the project, reopened the...
2
by: Fox1977 | last post by:
Hi folks, Just wondering if anyone can help me out with this problem I'm having getting a particular .net web application to run on a windows 2003 r2 x64 platform running as a domain account. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...

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.