为什么访问路径被拒绝? [英] Why is access to the path denied?

查看:332
本文介绍了为什么访问路径被拒绝?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有哪里我想删除我的文件有问题,但我得到一个异常。

I am having a problem where I am trying to delete my file but I get an exception.

if (result == "Success")
{
     if (FileUpload.HasFile)
     {
         try
         {
              File.Delete(Request.PhysicalApplicationPath + app_settings.login_images + txtUploadStatus.Text);
              string filename = Path.GetFileName(btnFileUpload.FileName);
              btnFileUpload.SaveAs(Request.PhysicalApplicationPath + app_settings.login_images + filename);
         }
         catch (Exception ex)
         {
               Message(ex.ToString());
         }
      }
}

另外我要指出,我试图从删除的文件夹具有完全控制的网络服务。

Also I should note that the folder I am trying to delete from has full control to network services.

完整的异常消息是:

System.UnauthorizedAccessException:对路径C:\\用户\\ gowdyn \\文档\\ Visual Studio 2008的\\项目\\混合\\混合\\ temp_loginimages \\ enviromental.jpg'被拒绝。在System.IO .__ Error.WinIOError(的Int32错误code,字符串maybeFullPath)在System.IO.File.Delete(字符串路径)在hybrid.User_Controls.Imgloader_Add_Edit_Tbl.btnUpdate_Click(对象发件人,EventArgs e)在C:\\用户\\ gowdyn \\文档\\ Visual Studio 2008的\\项目\\混合\\混合\\ User_Controls \\ Imgloader_Add_Edit_Tbl.ascx.cs:行242

System.UnauthorizedAccessException: Access to the path 'C:\Users\gowdyn\Documents\Visual Studio 2008\Projects\hybrid\hybrid\temp_loginimages\enviromental.jpg' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.File.Delete(String path) at hybrid.User_Controls.Imgloader_Add_Edit_Tbl.btnUpdate_Click(Object sender, EventArgs e) in C:\Users\gowdyn\Documents\Visual Studio 2008\Projects\hybrid\hybrid\User_Controls\Imgloader_Add_Edit_Tbl.ascx.cs:line 242

任何想法?

推荐答案

我也有这个问题,所以我磕磕绊绊对这个职位。我加code以下前行和复制/删除。

I also had the problem, hence me stumbling on this post. I added the following line of code before and after a Copy / Delete.

删除

File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);

复制

File.Copy(file, dest, true);
File.SetAttributes(dest, FileAttributes.Normal);

这篇关于为什么访问路径被拒绝?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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