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.
The full exception message is:
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
Any ideas?
I too faced the same problem when trying to do this after deployment at server:
I granted permission in IIS to other group including administrator and my problem got solved.
I got this error and solved it in just a moment. Don't know why all of my folders are read-only,I cancelled the read-only and apply it. However, it is still read-only. So I moved the file into the root folder, it works - so weird.
I have found that this error can occur in DESIGN MODE as opposed to ? execution mode... If you are doing something such as creating a class member which requires access to an .INI or .HTM file (configuration file, help file) you might want to NOT initialize the item in the declaration, but initialize it later in FORM_Load() etc... When you DO initialize... Use a guard IF statement:
This will keep the MSVS Designer from trying to create an INI or HTM file when you are in design mode.
I had the same problem on a newly moved website on a shared server. Solved through the web host panel (DotNetPanel) setting true the "allow write permissions". So if you are in a shared server before reviewing all code worth taking a look at the server configuration and could save you a lot of time.
I also had the problem, hence me stumbling on this post. I added the following line of code before and after a Copy / Delete.
Delete
Copy
First just check the path if the colon(:) character is missing or not after the drive letter. If colon is not missing then you can check if access/write permission is granted for that path. I had the same issue and i was only missing the colon, permission and everything else was fine.
will work fine but,
will give you access denial error.