Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hi All,
 
I have a list of files in root folder. I need to delete the file from that root folder. Its working fine in my local machine. But it shows error in server .
 
I use the below code
 

string filePath = (sender as LinkButton).CommandArgument;
              File.Delete(filePath);
              Response.Redirect(Request.Url.AbsoluteUri);
 

Please help me to delete file from server.mappath
 
Thanks
Mohan
Posted 12-Feb-13 17:14pm
V Mohan500
Edited 13-Feb-13 1:58am
joe_j4K
v2
Comments
Guirec Le Bars at 12-Feb-13 22:43pm
   
does the account (user) running the IIS process has any right on that directory? On your local mahine you are probably admin so it definitely works.
V Mohan at 12-Feb-13 23:56pm
   
Yes. I changed the permission in IIS. its working fine. Thanks
sahabiswarup at 12-Feb-13 23:36pm
   
for this you need to modify your web.config as well as give full permission from your CPanel so that you can delete file from server.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You should have access on the server and the folder in which you would want to delete the files from.
 
Does your code above
string filePath = (sender as LinkButton).CommandArgument;
return the right path of the file?
 
It has to match the below
File.Delete(Server.MapPath("~/temp/") + newTempFile)
where "~/temp/" is the sub-folder within the root folder that has all the files to delete and newTempFile is the actual file name eg. "123.xls"
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100