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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:16:52+00:00 2026-06-11T19:16:52+00:00

I am currently working on a Windows Forms application (C#, VS 2010) and I

  • 0

I am currently working on a Windows Forms application (C#, VS 2010) and I need to create functionality that enables users to upload .pdf, .exe files into a SQL Server 2008 database and download them back.

The problem that I have is that the file downloaded from the database is always corrupted (except .txt file) even though they are the same size. And I have used varbinary(MAX) as the file type to store the data in the database.

Can anyone show me some example code for how to do this?

PS: I have researched for more than a week, but still cannot find a solution to my problem, can anyone please help? Any answer will be highly appreciated.

  • 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-11T19:16:53+00:00Added an answer on June 11, 2026 at 7:16 pm

    In the below example there are a few assumptions made:

    1. I’m using Dapper for the database access. It extends any IDbConnection object.
    2. I have a table in the database that has a definition as such CREATE TABLE Data (Id INT IDENTITY(1, 1) PRIMARY KEY, Data VARBINARY(MAX)).
    3. Here is the documentation for ReadAllBytes

    So, obviously since you didn’t provide anything surrounding your table structure you’re going to have to change this code to meet you needs, but it will get you started.

    Writing It

    this.connection.Open();
    
    try
    {
        var parameters = new
            {
                Data = File.ReadAllBytes(...);
            };
        return connection.Execute("INSERT INTO Data (Data) VALUES (@Data)", parameters);
    }
    finally
    {
        this.connection.Close();
    }
    

    Reading It

    this.connection.Open();
    
    try
    {
        var parameters = new { Id = 1 };
        return connection.Query(
            "SELECT Data FROM dbo.Data WHERE Id = @Id", parameters)
            .Select(q => q.Data as byte[])
            .Single();
    }
    finally
    {
        this.connection.Close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a Windows Forms application and I need to have a
We're currently working on exposing the functionality of a Windows Forms application via WCF
I'm currently working on an application that needs to use Windows and Forms authentication
Currently I am working with: C# Windows forms application I currently have a problem
On the application I am currently working on, we need a way for users
I'm developing a windows forms application using VB.NET. I'm currently working on DataReport (by
I am currently working on a Windows.Forms application. It's basically a simple motion detection
I'm currently working on a windows application which is entirely model, that is, it
I'm currently working on an application that uses a Windows Form GUI. The main
I'm currently working on databinding some of my existing Windows Forms, and I've ran

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.