Click here to Skip to main content
15,895,779 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends,
While iam deleteing a file in gridview (websited hosted) i cant able to delete the file.its saying 404 - File or directory not found.but in locally i can able to delete.
Pleas help me guys..

C#
string path = Server.MapPath(PhotoPath + value3.Text);//"~/Admin/Content/Activites/Gallery/SportsGallery/images/" + value3.Text);

                       System.IO.File.Delete(path);

                       string path1 = Server.MapPath(ImagePath + value3.Text);//"~/Admin/Content/Activites/Gallery/SportsGallery/" + value3.Text);

                       System.IO.File.Delete(path1);
Posted
Comments
Sergey Alexandrovich Kryukov 2-Mar-15 11:27am    
We don't have access to your host's file system. You should know better where your files are. Just check up everything more thoroughly. There is nothing inherently wrong with your code.
—SA

Please see my comment to the question and also remember one more thing: '~' in the path used as an argument to MapPath is the root directory set up for your site, not your host's file system root. And normally you cannot access any files outside your site's root, as your ASP.NET code is executed in sandboxed environment which limits the access to any other file system objects, no matter what permissions are.
—SA
 
Share this answer
 
Does your application have permissions to perform transactions on the target folder? Most hosts provide a way to set folder permissions, such as read, write, read/write, read/execute, etc. Check the permissions for the folder and see if they need to be modified. While your user account might give you the ability to perform file management activities, your application might not the same rights.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900