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 8488969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:41:48+00:00 2026-06-10T21:41:48+00:00

Hi all i am working on mvc3 here i need to delete a previously

  • 0

Hi all i am working on mvc3

here i need to delete a previously uploaded file from the sessions data

anh i am displaying the file before inserting into data base so i am displaying the data in sessions now i need to delete the previously selected file plz help to how to get the selected file index value to delete the file from the sessions

For example here check this post it is in c# but i need this is in mvc3 please help me to do this work plz help me anyone

here my models are

 using System;
  using System.Collections.Generic;
   using System.Linq;
  using System.Web;
   using System.ComponentModel.DataAnnotations;

   namespace BugTracker.Models
 {
public class BugModel
{


    public BugModel()
    {
        if (ListFile == null)
            ListFile = new List<BugAttachment>();
    }
    public List<BugAttachment> ListFile { get; set; }

    public string ErrorMessage { get; set; }
}

public class BugAttachment
{
    public string FileName { get; set; }
    public int BugAttachmentID { get; set; }
    public string AttachmentName { get; set; }
    public int BugID { get; set; }
    public string AttachmentUrl { get; set; }
    public string AttachedBy { get; set; }
}

}

here my controllers

      public ActionResult UploadFile(string AttachmentName, BugModel model)
        BugModel bug = null;
        if (Session["CaptureData"] == null)
        {
            bug = model;
        }
        else
        {

            bug = (BugModel)Session["CaptureData"];
        }
        foreach (string inputTagName in Request.Files)
        {
            HttpPostedFileBase file1 = Request.Files[inputTagName];
            if (file1.ContentLength > 0)
            {
                BugAttachment attachment = new BugAttachment();
                var allowedExtensions = new[] { ".doc", ".xlsx", ".txt", ".jpeg", ".docx" };
                var extension = Path.GetExtension(file1.FileName);
                if (!allowedExtensions.Contains(extension))
                {
                    model.ErrorMessage = "{ .doc, .xlsx, .txt, .jpeg }, files are allowed.... ";
                }
                else
                {
                    string filename = Guid.NewGuid() + Path.GetFileName(file1.FileName);
                    string path = "/Content/UploadedFiles/" + filename;
                    string savedFileName = Path.Combine(Server.MapPath("~" + path));
                    file1.SaveAs(savedFileName);
                    attachment.FileName = "~" + path.ToString();
                    attachment.AttachmentName = AttachmentName;
                    attachment.AttachmentUrl = attachment.FileName;
                    bug.ListFile.Add(attachment);
                    model = bug;
                }
                Session["CaptureData"] = model;
            }

        }
        ModelState.Clear();

        return View("LoadBug", bug);
    } 

and here my view page

    <div class="UploadMain">
    <%:Html.Label("Attachment Name:") %>
    <%:Html.TextBoxFor(model=>model.AttachmentName) %>
    <span>
        <%:Html.Label("Upload Files") %></span>
    <input type="file" name="file" id="file" />
    <input type="submit" value="Upload" id="Upload" class="style-name cancel"  />
    <%--onclick="window.location.href='<%= Url.Action("UploadFile", "Bug") %>';"--%>
    <table align="center" class="gridtable" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <th>
                Attachment Name
            </th>
            <th>
                Attachment Url
            </th>
            <th>
            Action 
            </th>
        </tr>
        <% if (Model != null && Model.ListFile != null)
           {  %>
        <% foreach (var Emp in Model.ListFile)
           { %>
        <tr class="Data">
            <td >
                <%:Emp.AttachmentName %>
            </td>
            <td >
                <%: Emp.FileName %>
            </td>
           <td>
          <%-- <%= Html.ActionLink("Delete", "Delete")%>--%>

            <%:Html.ActionLink("Delete", "Delete", new { @FileName = Emp.FileName })%>


            </td>
        </tr>
        <% } %>
        <% } %>
    </table>
</div> 

For example here check this post it is in c# but i need this is in mvc3 please help me to do this work plz help me anyone

thanks in advance

  • 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-06-10T21:41:48+00:00Added an answer on June 10, 2026 at 9:41 pm

    To delete a file you uploaded all you need is its filepath, and use File.Delete(“filepath”);
    To know which file to delete your Delete action should take an id:

    Delete(int id)

    Then in your action link pass the BugAttachmentID: (using route values/parameters)

    <%:Html.ActionLink("Delete", "Delete", new { @FileName = Emp.FileName }, new { id = Emp.BugAttachmentID })%>
    

    Then in your delete method you use the ID to find the file in the FileList you want to delete. And then call File.Delete using the attachment url.

    I hope this helps.

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

Sidebar

Related Questions

I'm working on a wiki project. MVC3 + EF4 Code First. All classes from
This was all working before and all the sudden it stopped working and I
Here is my dilemma, I am working on some SaaS using ASP.net MVC3 and
So far I've been working with MVC3 with Linq to Sql so that all
I'm working on a asp.net mvc3 solution that has 3 projects Data, Service, and
I'm working on a MVC3 application and I created my POCO classes from my
Currently all working with my jquery $.post actions, successful connections, query and json_encode return
They were all working fine on my XAMMP sandbox but now nothing. Something im
We have three developers and one tester all working against the same database. We
My wordpress*(a custom template)* nav is all working on all of the pages but

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.