Click here to Skip to main content
15,921,622 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
How to delete file from folder using javascript?

Please send me the sample code
Posted
Comments
Dave Kreskowiak 15-Jan-16 16:30pm    
Delete a file where? On the server? On the client machine from inside a browser?
Sergey Alexandrovich Kryukov 15-Jan-16 22:16pm    
Where this JavaScript is hosted?
—SA

1 solution

Assuming this code is running in a web browser, as per your previous question:

Files on the client
Javascript running in a browser cannot delete files on the client. If it could, this would be a major security vulnerability.

Files on the server
The answer is the same as Ryan's reply to your previous question[^]: use jQuery's .ajax method[^], or something similar, to call code running on the server to instruct it to delete the file.

Don't allow the service to accept the path of the file to delete, as this would potentially allow hackers to delete important files from your application. Instead, have the path of the file hard-coded in the service, or stored in a server-side configuration file.

Make sure your application pool is running as a user which has sufficient permissions to delete the file.

Take any necessary precautions to prevent unauthorised users from calling the service.
 
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