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

  • Home
  • SEARCH
  • 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 9236051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:11:47+00:00 2026-06-18T07:11:47+00:00

I am creating an application in c# with mvc 2010 Express and at some

  • 0

I am creating an application in c# with mvc 2010 Express and at some point, the user can upload a file and open/download it to/from the database.
Here is the table in which I store the files:

CREATE TABLE [dbo].[tClientsFiles](  
    [IdClient] [int] NOT NULL,  
    [IdFile] [int] IDENTITY(1,1) NOT NULL,  
    [Name] [varchar](256) NULL,  
    [Type] [varchar](256) NULL,  
    [Lenght] [money] NULL,  
    [Content] [varbinary](max) NULL,  
    [DateAdd] [datetime] NULL,  
    [UserAdd] [varchar](50) NULL)  

In tClientsFiles.Name, I store the path and name of the file with: uploadFile.FileName;, where uploadFile is an HttpPostedFileBase. So for insance, if the file is Test.txt and it is in the User’s Desktop, it stores C:\Users\user\Desktop\test.txt

Then, when viewing/downloading the file, I have a link to an ActionResult in my Controller:

public ActionResult GetFile(int id)
    {
        var file = dre.tClientsFiles.First(m => m.IdFile == id);

        MemoryStream ms = new MemoryStream(file.Content, 0, 0, true, true);
        Response.ContentType = file.Type;
        Response.AddHeader("content-disposition", "attachment;filename=" + file.Name);
        Response.Buffer = true;
        Response.Clear();
        Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
        Response.OutputStream.Flush();
        Response.End();
        return new FileStreamResult(Response.OutputStream, file.Type);
    }

When opening the file, it names it with its “Name” file.Name, like this: c_Users_user_Desktop_Test.

My question is: is there a way (maybe modifying my Response.AddHeader) to name it with just its “real name”? (I mean, in our example: Test)
Or maybe a way to store the Name in a different way so that it just stores its “real name” instead of the name and its whole path?

Thanks a lot for your time!

  • 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-18T07:11:48+00:00Added an answer on June 18, 2026 at 7:11 am

    Try

    Response.AddHeader("content-disposition", "attachment;filename=" + Path.GetFileName(file.Name));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently creating an application using ASP.NET MVC. I got some user input inside
I'm creating application with Codeigniter and MVC pattern. I'm at the point where I
Suppose I am creating a application using the sample Northwind database using asp.net mvc
I'm creating an MVC application that's following a RESTful URL approach. I am experiencing
I am working on creating an MVC application for an existing Bug tracker of
I'm currently creating an MVC application that will likely to expand to include a
I'm creating a web application using spring mvc. I have started to incorporate the
I am creating a asp.net mvc application and loaded the data into jqgrid and
I am creating an ASP.NET MVC application that has postcode lookup functionality. I capture
I am creating a simple application using the MVC design pattern where my model

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.