使用C#在Asp.Net中删除文件ion Web [英] Delete file ion Web in Asp.Net using C#

查看:64
本文介绍了使用C#在Asp.Net中删除文件ion Web的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经写了这段代码

Hi
I have written this code

protected void BtnDelete_Click(object sender, EventArgs e)
   {
       File.Delete(Server.MapPath("~/Documents/") + "lnkAttachment.Text");

   }


它不是删除文件.其次,我想给用户一个删除或不删除它的机会.
Thanx


It is not deleting file . Secondly i want to give user a chance whether he wants to delete it or not.
Thanx

推荐答案

您需要为IIS分配访问该文件夹的权限,以删除该文件

在此处阅读更多信息
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.


1.
System.IO.FileInfo f = new System.IO.FileInfo("your file path");
           f.Delete();



2.将按钮的OnClientClick属性设置为
OnClientClick ="return javascript:confirm(``确定要删除吗?")";



2. Set button''s OnClientClick property as
OnClientClick ="return javascript:confirm(''Are you sure to delete?'')";


临时ASP.NET文件文件夹(c:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Temporary ASP.NET Files)就是这里出现问题的那个.首先,我认为问题与文件夹的安全权限有关,我是对的.

我右键单击"ASP.NET临时文件"文件夹,然后转到安全性"选项卡.我注意到有一个名为IIS_IUSRS的用户,并且该人具有完全控制权限.但是显然这还不够.

临时ASP.NET文件和C:\ Windows \ temp文件夹应具有具有完全控制权限的IIS_WPG和NETWORK SERVICE用户.我不知道为什么C:\ Windows \ temp文件夹需要它,但是我不遗余力尝试找到它.相反,我正在撰写有关该问题的博客文章.也许后者我也会去解决这个问题

应用这些设置后,请重新启动IIS,然后尝试再次运行您的应用程序.该错误现在应该消失了.

试图找到解决问题的正确方法使我遭受了很多痛苦,希望您不必为此烦恼.



参考:
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[^]


这篇关于使用C#在Asp.Net中删除文件ion Web的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆