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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:49:11+00:00 2026-05-23T08:49:11+00:00

I am trying to store pdf files in sql server. I am using an

  • 0

I am trying to store pdf files in sql server.
I am using an asp.net mvc 2 application with sql server? Can you show me some links to code samples?

  • 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-23T08:49:11+00:00Added an answer on May 23, 2026 at 8:49 am

    The answer will depend very much on what technology you use to access this SQL Server, whether you are using an ORM, etc… Because you haven’t provided any such information in your question, let me illustrate an example of how to do this using plain ADO.NET.

    You could start with a form:

    <% using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" })) { %>
        <label for="file">Select a pdf file:</label>
        <input type="file" name="file" id="file" />
        <input type="submit" value="Upload" />
    <% } %>
    

    and a controller action to handle the submission of this form:

    [HttpPost]
    public ActionResult Index(HttpPostedFileBase file)
    {
        if (file != null && file.ContentLength > 0)
        {
            var fileName = Path.GetFileName(file.FileName);
            var extension = Path.GetExtension(fileName);
            var document = new byte[file.InputStream.Length];
            file.InputStream.Read(document, 0, document.Length);
            if (string.Equals(".pdf", extension, StringComparison.OrdinalIgnoreCase))
            {
                using (var conn = new SqlConnection(SomeConnectionString))
                using (var cmd = conn.CreateCommand())
                {
                    conn.Open();
                    cmd.CommandText = "INSERT INTO Documents (document) VALUES (@document);";
                    cmd.Parameters.Add("@document", SqlDbType.Binary, 20).Value = document;
                    cmd.ExecuteNonQuery();
                }
            }
        }
        return View();
    }
    

    Of course the SQL part should be externalized into a separate repository to avoid cluttering the controller action with such code. Also if you are using SQL Server 2008 you might take a look at the new FILESTREAM type which is more adapted to this sort of things.

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

Sidebar

Related Questions

I'm trying to store a file in an SQL Server database and am using ASP.NET
I'm trying to implement PDF functionality to my application. So, I added some new
I'm trying to save a dynamic pdf file generated from a web server using
I'm trying to store the names of some variables inside strings. For example: Dim
I am trying to store/retrieve a value that is stored in the Application Settings.
For example, one application that I'm working on stores PDF files into a database,
I'm trying to zip a large number of pdf files (stored as BLOBs in
i am trying to store some method callbacks but referring to it will keep
I am using ASP .Net 3.5 MVC1 with a DB2 backend. My company is
I'm using a handler(.ashx) to serve some files. I have a folder where I

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.