Click here to Skip to main content
13,410,124 members (38,090 online)
Rate this:
Please Sign up or sign in to vote.
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

Posted 12-Feb-13 17:14pm
Updated 13-Feb-13 1:58am
Guirec Le Bars 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

Rate this: bad
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"

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180221.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2018
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