Click here to Skip to main content
15,792,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;

Please help me to delete file from server.mappath

Updated 13-Feb-13 1:58am
Guirec 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 12-Feb-13 23:56pm    
Yes. I changed the permission in IIS. its working fine. Thanks
sahabiswarup 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

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"
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