473,666 Members | 2,238 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem in Deleting Files

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 delete the file. Please give me any suggestion.

FileInfo objectFile = new FileInfo(strFil ePath); objectFile.Dele te();

//This throws an Exception that Access to the file is denied on line
objectFile.Dele te()

Thanks,
Sandeep Singh Sekhon
Jul 29 '06 #1
5 2101

The .NET Framework runs all ASP.NET processes under the local ASPNET
account. You may have to grant write access to asp.net account to the folder
where you are deleting/ writing the file. The asp.net account varies
depending on which operating system the web server is hosted in
(xp/win2003).

-Hitesh Ramchandani.
"Sandeep Singh Sekhon" <ef*****@newsgr oups.nospamwrot e in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>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 delete the file. Please give me any suggestion.

FileInfo objectFile = new FileInfo(strFil ePath); objectFile.Dele te();

//This throws an Exception that Access to the file is denied on line
objectFile.Dele te()

Thanks,
Sandeep Singh Sekhon

Jul 29 '06 #2
Thanks for Hitesh's inputs.

Hi Sandeep,

For such file deleting Access_Denied error, it has the following possible
causes:

1. The current ASP.NET application's running security identity doesn't have
the sufficient permission to delete the target file. Genernally if you're
not using impersonate in your ASP.NET application, the current security
context of the application is the worker process's identity. You can check
your ASP.NET application's worker process identity according to the
following MSDN article:

#Configuring ASP.NET Process Identity
http://msdn2.microsoft.com/en-us/library/dwc1xthy.aspx

Also, a simple means to get the current process identity is execute the
following code in your page to printout the current security context:

==========
protected void Page_Load(objec t sender, EventArgs e)
{
Response.Write( "<br/>Security Identity: " +
System.Security .Principal.Wind owsIdentity.Get Current().Name) ;
}
===========

After you've determined the security identity, verify that whether this
identity(accoun t) has the sufficient permission to manipulate the target
files or folder).

BTW, for tracing file access permission issue, the filemon utility is quite
common and useful:

http://www.sysinternals.com/utilities/filemon.html

2. Suppose the security identity has the sufficient permission to
manipulate the target file, it is possible that the file's filehandle is
locked by some other process which make the ASP.NET process fail to acquire
the file handle. To check file handle lock/ownership, the processexplorer
utility is a helpful one:

#How To Determine File Handle Ownership
http://support.microsoft.com/kb/q232830/

http://www.sysinternals.com/Utilitie...sExplorer.html

Please have a look at the above things. If you have anything unclear or if
you meet any further problems, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial

response from the community or a Microsoft Support Engineer within 1
business day is

acceptable. Please note that each follow up response may take approximately
2 business days

as the support professional working with you may need further investigation
to reach the

most efficient resolution. The offering is not appropriate for situations
that require

urgent, real-time or phone-based interactions or complex project analysis
and dump analysis

issues. Issues of this nature are best handled working with a dedicated
Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.


Jul 31 '06 #3
Hitesh Ramchandani wrote:
The .NET Framework runs all ASP.NET processes under the local ASPNET
account. You may have to grant write access to asp.net account to the folder
where you are deleting/ writing the file. The asp.net account varies
depending on which operating system the web server is hosted in
(xp/win2003).

-Hitesh Ramchandani.
"Sandeep Singh Sekhon" <ef*****@newsgr oups.nospamwrot e in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>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 delete the file. Please give me any suggestion.

FileInfo objectFile = new FileInfo(strFil ePath); objectFile.Dele te();

//This throws an Exception that Access to the file is denied on line
objectFile.Del ete()

Thanks,
Sandeep Singh Sekhon

hi Hitesh,
I am using Windows XP Prof. How can I grant write access to
ASP.NET account for deleting the file.
Thanks,
Sandeep
Aug 1 '06 #4
Hi Sandeep,

Have you had a chance to have a look at my previous reply ,either? In my
last message, I've listed some suggestion on how to determine the ASP.NET
application's worker process identity or security context. Then, checking
whether that identity/account has sufficient permission to modify the
target directory. In addition, the "filemon" utility I mentioned earlier
is a good tool for tracing file access failure (you can find which account
failed to access which file on the machine). In case you haven't found my
last reply, here is a copy from the former message:
############### ############### ############### ############### #
Hi Sandeep,

For such file deleting Access_Denied error, it has the following possible
causes:

1. The current ASP.NET application's running security identity doesn't have
the sufficient permission to delete the target file. Genernally if you're
not using impersonate in your ASP.NET application, the current security
context of the application is the worker process's identity. You can check
your ASP.NET application's worker process identity according to the
following MSDN article:

#Configuring ASP.NET Process Identity
http://msdn2.microsoft.com/en-us/library/dwc1xthy.aspx

Also, a simple means to get the current process identity is execute the
following code in your page to printout the current security context:

==========
protected void Page_Load(objec t sender, EventArgs e)
{
Response.Write( "<br/>Security Identity: " +
System.Security .Principal.Wind owsIdentity.Get Current().Name) ;
}
===========

After you've determined the security identity, verify that whether this
identity(accoun t) has the sufficient permission to manipulate the target
files or folder).

BTW, for tracing file access permission issue, the filemon utility is quite
common and useful:

http://www.sysinternals.com/utilities/filemon.html

2. Suppose the security identity has the sufficient permission to
manipulate the target file, it is possible that the file's filehandle is
locked by some other process which make the ASP.NET process fail to acquire
the file handle. To check file handle lock/ownership, the processexplorer
utility is a helpful one:

#How To Determine File Handle Ownership
http://support.microsoft.com/kb/q232830/

http://www.sysinternals.com/Utilitie...sExplorer.html

Please have a look at the above things. If you have anything unclear or if
you meet any further problems, please feel free to post here.

Sincerely,

Steven Cheng
############### ############### ############### ##############

Please feel free to let me know if you have anything unclear here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Aug 1 '06 #5
Hi Sandeep,

Have you got any progress on this issue? Please feel free to post here if
there is still any problem.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 3 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
9509
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?
0
1398
by: Hrvoje Vrbanc | last post by:
Hello, this is a problem I came upon while building a site based on MCMS 2002 but it's not strictly MCMS-oriented: I have a page that displays a certain content in presentation mode but when an editor clicks "Switch To Edit Site" in MCMS console on the page, the page displays a different content, an interface that editor use for upload and deleting files on the web server. There are no problems with the upload but there is a problem...
0
939
by: rahuldhammy | last post by:
I am implementing a personalization(customizing the contents of the web site according to the user choice)in asp.net web site.For this i have to delete modify some files in my App_Themes folder.I am trying to do this with my c# code.But i always get some exception while deleting the files from the App-Themes folder.Even if the files are deleted it gives the call to Application_Start in global.asax.It seems application restarts if any change is...
0
847
by: rahuldhammy | last post by:
I am implementing a personalization(customizing the contents of the web site according to the user choice)in asp.net web site.For this i have to delete modify some files in my App_Themes folder.I am trying to do this with my c# code.But i always get some exception while deleting the files from the App-Themes folder.Even if the files are deleted it gives the call to Application_Start in global.asax.It seems application restarts if any change is...
4
1689
by: vijayarl | last post by:
Hi Everyone, i have written small code where it fetches the required files from required dir path & deleting those files before proceeding further. script goes like this: my $@file_names; my $full_path; my $dir = "c:\\svap\\input\\";
0
8355
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
8866
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
8781
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
8638
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
7381
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
6191
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
5662
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
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.