Click here to Skip to main content
15,915,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have written this code
C#
protected void BtnDelete_Click(object sender, EventArgs e)
   {
       File.Delete(Server.MapPath("~/Documents/") + "lnkAttachment.Text");

   }

It is not deleting file . Secondly i want to give user a chance whether he wants to delete it or not.
Thanx
Posted
Updated 31-Jan-12 1:32am
v2

You need to assign the permissions to IIS to access the folder to delete this file

Read more here http://www.tugberkugurlu.com/archive/local-iis-7-0-cs0016--could-not-write-to-output-file-microsoft-net-framework-v4-0-30319-temporary-asp-net-files[^]

Secondly, this code will delete the file on the server where the site is hosted and NOT on user's machine.

You can display a javascript confirm box to the user to check if he really wants to delete the file.
 
Share this answer
 
1.
C#
System.IO.FileInfo f = new System.IO.FileInfo("your file path");
           f.Delete();


2. Set button's OnClientClick property as
OnClientClick ="return javascript:confirm('Are you sure to delete?')";
 
Share this answer
 
Temporary ASP.NET Files folder (c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files) was the the one with the problem here. First, I thought that the problem is related to security permissions on the folder and I was right.

I right clicked on the Temporary ASP.NET Files folder and go to the security tab. I noticed that there is user called IIS_IUSRS and that guy has the full control permission. But apparently that was not enough.

The Temporary ASP.NET Files and C:\Windows\temp folders should have IIS_WPG and NETWORK SERVICE users with the full control permission. I have no idea why C:\Windows\temp folder needs that but I have no effort left to try to find that. Instead, I am writing a blog post about the problem. Maybe latter I will get to that and figure it out, too

Once you applied those setting, restart your IIS and try to run your application again. The error should be gone by now.

I suffered a lot by trying to find the right method for the problem and I hope you didn’t have to go through hell over this.

edit:

Reference : http://www.tugberkugurlu.com/archive/local-iis-7-0-cs0016--could-not-write-to-output-file-microsoft-net-framework-v4-0-30319-temporary-asp-net-files[^]
 
Share this answer
 
v2
Comments
bbirajdar 31-Jan-12 9:47am    
Added the link to the reference...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900