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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:47:35+00:00 2026-05-25T14:47:35+00:00

My ASP.NET MVC app accepts files uploaded and stores these in a single folder.

  • 0

My ASP.NET MVC app accepts files uploaded and stores these in a single folder. However I want to ensure that when a user uploads a file the app accepts any filename, however this will fail when users try upload files with the same file name.

I guess I could create separate folders for each file but I’d like a clean and flat directory structure. Currently I append a GUID to the file name but this isn’t a nice solution as it results in weird filenames when a user downloads a file.
I thought about storing the file data in a database and then writing it out to a file when it was requested, but this is a lot of overhead.

Any alternative approaches?

  • 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-25T14:47:36+00:00Added an answer on May 25, 2026 at 2:47 pm

    In order to keep your directory structure flat store your files by appending a GUID (as you already did). In your download handler (controller action method) first convert the GUID based file name to the original file name by removing the GUID from the file name. Then use the FileContentResult class to transfer the file. You can set the FileDownloadName property to specify the file name for the file to transfer. In fact the FileDownloadName property sets the Content-Disposition header under the hood.

    Here is a small code example (action method of your download controller class):

    string fileToDownload = "test.jpg_4274B9D4-9084-441C-9617-EAD03CC9F47F";
    
    string originalFileName = fileToDownload.Substring(0, fileToDownload.LastIndexOf('_'));
    
    FileContentResult result = new FileContentResult(
        System.IO.File.ReadAllBytes(Server.MapPath(String.Format("~/files/{0}", fileToDownload))), "application/binary");
    
    result.FileDownloadName = originalFileName; // Sets the Content-Disposition header
    
    return result;
    

    The user downloading the file is prompted to open/save a file with the original file name.

    Hope, this helps.

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

Sidebar

Related Questions

I have an asp.net MVC App that I want to deploy to IIS 5
I have an ASP.NET MVC app that stores all SQL DateTime in UTC, so
In my asp.net mvc app I want to check if a certain url returns
I have an asp.net mvc app running on a local iis website that is
Assume I have an ASP.NET MVC app that's not doing anything too fancy (no
I have an ASP.NET MVC app that opens a Request view in a new
I have an asp.net mvc app that is built to run as standard web
I have an ASP.NET MVC app and I want to add to each page
I am building an ASP.Net MVC app that will run on a shared hosting
I have an ASP.Net MVC app, and i have some xsl files inside of

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.