简体   繁体   English

如何使用asp.net删除文件?

[英]How to Delete a file using asp.net?

i write the code in asp.net using c# to delete the file in my computer, but it is not deleting please help me thank u. 我使用c#在asp.net中编写代码来删除我的计算机中的文件,但它没有删除请帮助我谢谢你。 this is my code, i write in button click event 这是我的代码,我在按钮点击事件中写

        string path = "E:\\sasi\\delt.doc";
        FileInfo myfileinf = new FileInfo(path);
        myfileinf.Delete();
public void DeleteFileFromFolder(string StrFilename)
{

    string strPhysicalFolder = Server.MapPath("..\\");

    string strFileFullPath = strPhysicalFolder + StrFilename;

    if (IO.File.Exists(strFileFullPath)) {
        IO.File.Delete(strFileFullPath);
    }

}

In order to delete a file you must ensure that the account has sufficient permissions. 要删除文件,您必须确保该帐户具有足够的权限。 In general ASP.NET applications run under limited permission account such as Network Service . 通常,ASP.NET应用程序在有限的权限帐户(如Network Service下运行。 For example if your application runs under IIS 6 you could go to the Administration Console and set a custom account in the application pool properties: 例如,如果您的应用程序在IIS 6下运行,您可以转到管理控制台并在应用程序池属性中设置自定义帐户:

alt text http://i.msdn.microsoft.com/Bb969101.SharePoint_SQL_TshootingFig3%28en-US,SQL.90%29.jpg alt text http://i.msdn.microsoft.com/Bb969101.SharePoint_SQL_TshootingFig3%28en-US,SQL.90%29.jpg

You need to ensure that the account is member of the IIS_WPG group. 您需要确保该帐户是IIS_WPG组的成员。

Make sure the ASP user has permissions to this folder. 确保ASP用户具有此文件夹的权限。 By default this user is not given access to much of the harddrive.. 默认情况下,此用户无权访问大部分硬盘..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM