User1793652459 posted
Hello,
I have this code on on my HTML page, I am trying to run a function that would just delete all files from a network folder, no parameters are involved. When a user clicks on a Delete button on the page, it makes it to the alert box but never goes into
the controller and I keep getting a message that resource can't be found.
$scope.deleteFiles = function () {
alert('test')
var request = {
method: 'GET',
url: '/api/DeleteFiles/'
};
// SEND THE REQUEST.
$http(request)
.success(function (d) {
alert(d);
})
.error(function () {
});
}
I have these 2 functions in my Api controller but it never hits the delete function, however it goes into the upload function fine:
[Route("api/UploadFiles")]
[HttpPost]
public string UploadFiles()
{
.....
}
[Route("api/DeleteFiles")]
[HttpGet]
public string DeleteFiles()
{
string sPath = ""; // Doesn't hit this breakpoint
sPath = HostingEnvironment.MapPath("~/myFolder/");
if (File.Exists(sPath))
{
string[] files = Directory.GetFiles(sPath, "*.*");
foreach (string f in files)
{
File.Delete(f);
}
}
return "File Deleted";
}
Not sure what method I would use for just executing a function that returns a message after deletion. I have tried POST and GET without any luck. I am not sending any data, just need to call the function so it deletes files.
Thanks