Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6885965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:42:01+00:00 2026-05-27T05:42:01+00:00

I am invoking a action method via jquery and trying to delete a file.

  • 0

I am invoking a action method via jquery and trying to delete a file. But nothing happens. The file still exist.

Following is jquery Code

$("#pictureRemove").click(function (e) {
            $("#pictureImage").html("<img src='../../Content/Images/noDefaultImage_100.gif'/>");
            $(this).hide();
            $.ajax({
                type: 'POST',
                url: '@Url.Action("Remove", "Category")',
                data: { fileName: $('#pictureTitle').attr('src') },
                dataType: 'json'
                    // User your JSON response.
            });
        });

Following is the action method code

    [HttpPost]
    public ActionResult Remove(string fileName)
    {
        string completFileName = Server.MapPath("~/Content/Images/" + fileName);
        System.IO.File.Delete(completFileName);
        return Json(true);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:42:02+00:00Added an answer on May 27, 2026 at 5:42 am

    On this line:

    data: { fileName: $('#pictureTitle').attr('src') }
    

    you seem to be passing the fileName parameter to the controller action from the src parameter of some image. So I suppose that you have some image like this:

    <img id="pictureTitle" src="/Content/images/foo.jpg" />
    

    so you are passing /Content/images/foo.jpg so in your controller action you are trying to delete Server.MapPath("~/Content/Images//Content/images/foo.jpg") which is translated to c:\wwwroot\Content\Images\Content\images\foo.jpg which is unlikely to exist and an exception is thrown.

    Simply put a breakpoint in your controller action and inspect the different parameters.

    This being said exposing a controller action that takes a filename and deletes the file on the server is a huge security hole in your application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code prints (when invoking MyMethod): 0 0 0 1 I would expect
I am having problem invoking my Log-on action method, which is in a controller
I have a method invoking bean which calls a method to perform some sort
I've got a c# assembly which I'm invoking via COM from a Delphi (win32
I'm writing a jQuery UI plugin. Inside that plugin, when an action occurs, I'm
I have a problem while trying to render a partial action on my layout.
if I have a dispatcher invoking in background like this: Application.Current.Dispatcher.BeginInvoke(new Action(() => MethodToCall()),
In the following method I'm sending an enumeration of actions and want an array
I have an html form like this: <form id=boxy action=layout.html method=get accept-charset=utf-8> <input type=text
I am not sure what is going on but even though I am invoking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.