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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:02:44+00:00 2026-05-28T01:02:44+00:00

I Have an Upload Manager and I want to return a File when user

  • 0

I Have an Upload Manager and I want to return a File when user called a special Method of My Control Like this:

www.website.com/upload/getfile/?fileID=100

how Can I do this?
I want to know how Can I return a file!


I found my answer and I wrote the sample code below:

public FilePathResult GetFile(string Name)
    {
        FilePathResult s = new FilePathResult(@"C:/"+Name, "File");
        Response.Headers.Clear();

        return s;
    }

but there is a problem now.Is there any problem if I use File for my ContentType.Because I don’t know it.

  • 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-28T01:02:44+00:00Added an answer on May 28, 2026 at 1:02 am

    Make a controller named uploadController, with an action named getfile which has an argument.

    Then the above url can be changed to

    www.website.com/upload/getfile/100
    

    UPDATE:

    Change the return type of action to FileResult

    For complete answer take a look at part of my codebase:

    //Attachment Class
    public class Attachment
    {
        #region Properties
    
        public virtual Guid AttachmentId { get; set; }
        public virtual int? ContentLength { get; set; }
        public virtual string ContentType { get; set; }
        public virtual byte[] Contents { get; set; }
        public virtual DateTime? DateAdded { get; set; }
        public virtual string FileName { get; set; }
        public virtual string Title { get; set; }
    
        #endregion
     }
    
    
    public class AttachmentController : Controller
    {
         IAttachmentService attachmentService;
    
        public AttachmentController(IAttachmentService attachmentService)
        {
            this.attachmentService = attachmentService;
        }
    
        public ActionResult Index(Guid id)
        {
            var attachment = this.attachmentService.GetById(id);
            return attachment.IsNull() ? null : this.File(attachment.Contents, attachment.ContentType,attachment.FileName);
        }
    }
    
    public class AttachmentModelBinder : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            HttpRequestBase httpRequestBase = controllerContext.RequestContext.HttpContext.Request;
            HttpPostedFileBase @base = httpRequestBase.Files[bindingContext.ModelName];
            var converter = new FileConverter();
            Attachment attachment = converter.Convert(
                    new ResolutionContext(
                        new TypeMap(new TypeInfo(typeof(HttpPostedFileWrapper)), new TypeInfo(typeof(Attachment))),
                        @base,
                        typeof(HttpPostedFileWrapper),
                        typeof(Attachment)));
            }
            return attachment;
        }
    }
    
    public class MvcApplication : HttpApplication
    {
        protected void Application_Start()
        {
            ModelBinders.Binders[typeof(Attachment)] = new AttachmentModelBinder();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an upload box... <form action=upload_file.php method=post enctype=multipart/form-data><BR> <label for=file>Filename:</label><BR> <input type=file name=file
I have to upload a file to an FTP server. The filename contains special
So I have an upload script, and I want to check the file type
I have a file manager application that is writed by asp.net MVC. User can
I am using a File Upload script called Simple Photo Manager. When I upload
I have developed a download/upload manager script. When I upload a file via POST
I have a upload text file field, and with it I plan to save
I have an upload form with a file to be uploaded. The issue I
I have an upload script that write a index.html file, I modified it to
I have an upload form that takes a user about 30 min. to complete.

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.