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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:49:14+00:00 2026-05-17T14:49:14+00:00

I have a MVC 2 web application. The website captures grant applications for loans.

  • 0

I have a MVC 2 web application. The website captures grant applications for loans. With each application I can upload documents. The way that we upload documents to the database is as follows:

private IEnumerable<byte> GetStreamByteArrayData(Stream stream)
{
   byte[] buffer = new byte[8192];
   int bytesRead = 0;
   while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
   {
      for (int byteIndex = 0; byteIndex < bytesRead; byteIndex++)
      {
         yield return buffer[byteIndex];
      }
   }
}

The calling method looks like this:

Convert.ToBase64String(GetStreamByteArrayData(hpf.InputStream).ToArray());

In my grid that displays the uploaded documents I have the document name, mime type and so forth. What I am trying to do is to have the name of the document in a link. When the link is clicked then the document is opened. I have no idea how to do this in an MVC app.

Can someone please advise or provide some sample source code? All help would be appreciated.

Thanks.

  • 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-17T14:49:15+00:00Added an answer on May 17, 2026 at 2:49 pm

    Assuming that you have stored the name, mime type and contents of each document into the database you could have a controller action which will serve a file given it’s unique id:

    public ActionResult Download(int? id)
    {
        Document document = _repository.GetDocument(id);
        if (document == null)
        {
            throw new HttpException(404, "Not found");
        }
    
        // For example document.ContentType = "application/pdf" and 
        // document.Name = "test.pdf"
        return File(document.Contents, document.ContentType, document.Name);
    }
    

    The Document model might look something like this:

    public class Document
    {
        public int Id { get; set; }
        public byte[] Contents { get; set; }
        public string ContentType { get; set; }
        public string Name { get; set; }
    }
    

    And finally you could generate links to this action in your grid:

    <%: Html.ActionLink("Download", "Download", new { id = "123" })%>
    

    If you don’t have the content type and name of the document stored into the database you could pass them as action parameters:

    <%: Html.ActionLink("Download", "Download", 
        new { id = "123", contentType = "application/pdf", name = "test.pdf" }) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Spring Web MVC application that I'd like to serve a large,
I have a asp.net web application using MVC framework, the website allows the registrars
I have built an ASP.NET MVC 3 web application (with exlusively Razor/cshtml pages) that
I have an asp.net MVC web application that requires tasks to be scheduled. (A
I have developed a MVC web application with ASP.NET MVC and im just wondering
I have a Asp.net MVC web application, containing mostly text. I want to put
I have a Clustered Windows Hosting site which currently hosts an MVC Web Application
I have one question; In my ASP.NET MVC web application have to do certain
Here's what I'm trying to do. I have an ASP.NET MVC web application, where
I have created blank Asp.Net-MVC 3 web application and want to write my own

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.