File Delete Problem ??
-
Hi.. Friends.. When I delete file with C# code, I m getting error like "Access to the path 'g:\activewebroot\Active24\w11618838\web\content\File\xxx.zip' is denied." But I can upload new files on server, But I cant delete this files !! I dont know, Why this problem occurred ?? Please, Give me any solution ASAP. Thanks in Advance.
Regards, Abhi
Might be the file is open or in use close that file before trying delete that file
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Hi.. Friends.. When I delete file with C# code, I m getting error like "Access to the path 'g:\activewebroot\Active24\w11618838\web\content\File\xxx.zip' is denied." But I can upload new files on server, But I cant delete this files !! I dont know, Why this problem occurred ?? Please, Give me any solution ASAP. Thanks in Advance.
Regards, Abhi
-- Abhi -- wrote:
When I delete file with C# code, I m getting error like "Access to the path 'g:\activewebroot\Active24\w11618838\web\content\File\xxx.zip' is denied."
How you are giving file name :confused: ? ASP.NET will be having delete permissions only in the website, Not in all hard disk locations. When referring a path in ASP.NET always use
Server.MapPath()
to get files physical location on the server.
-
Might be the file is open or in use close that file before trying delete that file
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
No, Sandeep !! Not any files are open on the server. In my project, I have a admin panel.. With this, I m uploading file, and it uploads successfully... And Then, I m listing all files name and with button 'delete' for each file !! But when, I click on 'delete' button , I am deleting files from server by C# code..Then I got this error !!
Regards, Abhi
-
-- Abhi -- wrote:
When I delete file with C# code, I m getting error like "Access to the path 'g:\activewebroot\Active24\w11618838\web\content\File\xxx.zip' is denied."
How you are giving file name :confused: ? ASP.NET will be having delete permissions only in the website, Not in all hard disk locations. When referring a path in ASP.NET always use
Server.MapPath()
to get files physical location on the server.
No, Navneeth !! Not any files are open on the server. In my project, I have a admin panel.. With this, I m uploading file, and it uploads successfully... And Then, I m listing all files name and with button 'delete' for each file !! But when, I click on 'delete' button , I am deleting files from server by C# code..Then I got this error !! Regards, Abhi
Regards, Abhi
-
No, Sandeep !! Not any files are open on the server. In my project, I have a admin panel.. With this, I m uploading file, and it uploads successfully... And Then, I m listing all files name and with button 'delete' for each file !! But when, I click on 'delete' button , I am deleting files from server by C# code..Then I got this error !!
Regards, Abhi
Sorry i gave wrong reply but yo should have read/write/delete permision for that path to asp.net process Do one thing give all permision to Everyone then try if it delete the file then go specific
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
No, Navneeth !! Not any files are open on the server. In my project, I have a admin panel.. With this, I m uploading file, and it uploads successfully... And Then, I m listing all files name and with button 'delete' for each file !! But when, I click on 'delete' button , I am deleting files from server by C# code..Then I got this error !! Regards, Abhi
Regards, Abhi
-- Abhi -- wrote:
But when, I click on 'delete' button , I am deleting files from server by C# code..Then I got this error !!
Well, can you post that deletion code here ?
-
-- Abhi -- wrote:
But when, I click on 'delete' button , I am deleting files from server by C# code..Then I got this error !!
Well, can you post that deletion code here ?
Yes. Sure. System.IO.FileInfo objFileInfo = new System.IO.FileInfo(Server.MapPath("../File/") + Filename.ToString()); System.Security.Permissions.FileIOPermission fp = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.AllAccess, objFileInfo.Directory.FullName); objFileInfo.Delete();
Regards, Abhi
-
Yes. Sure. System.IO.FileInfo objFileInfo = new System.IO.FileInfo(Server.MapPath("../File/") + Filename.ToString()); System.Security.Permissions.FileIOPermission fp = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.AllAccess, objFileInfo.Directory.FullName); objFileInfo.Delete();
Regards, Abhi
-- Abhi -- wrote:
Server.MapPath("../File/") + Filename.ToString()
Have you printed out put of this line ? Are you getting a valid file path ?
-- Abhi -- wrote:
System.Security.Permissions.FileIOPermission fp = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.AllAccess, objFileInfo.Directory.FullName); objFileInfo.Delete();
Why all these ? Simply call
File.Delete(Path)
-
-- Abhi -- wrote:
Server.MapPath("../File/") + Filename.ToString()
Have you printed out put of this line ? Are you getting a valid file path ?
-- Abhi -- wrote:
System.Security.Permissions.FileIOPermission fp = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.AllAccess, objFileInfo.Directory.FullName); objFileInfo.Delete();
Why all these ? Simply call
File.Delete(Path)
Yes... This path works best in my Local project in my machine. But after uploading this project DLL to the server by FTP... Then I got error. I have used below code : System.Security.Permissions.FileIOPermission fp = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.AllAccess, objFileInfo.Directory.FullName); But, I cant find solution with above permission code, this code is meaning less.
Regards, Abhi
-
Hi.. Friends.. When I delete file with C# code, I m getting error like "Access to the path 'g:\activewebroot\Active24\w11618838\web\content\File\xxx.zip' is denied." But I can upload new files on server, But I cant delete this files !! I dont know, Why this problem occurred ?? Please, Give me any solution ASAP. Thanks in Advance.
Regards, Abhi
If you r writing this code in asp.net, so due to security reason this will not done, u have to use impersonation or check authentication mode. Muhammad Rashid