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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:54:45+00:00 2026-06-02T07:54:45+00:00

How to pass an Excel file from a WinForms client to a WCF service

  • 0

How to pass an Excel file from a WinForms client to a WCF service and into an SQL Server table?

Can anyone provide any guidance, code, or advice?

  1. WCF service contract and implementation that will take an Excel file as a parameter
  2. Contract implementation should insert that Excel file into a varbinary(MAX) column in SQL Server.
  • 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-02T07:54:46+00:00Added an answer on June 2, 2026 at 7:54 am

    I’m sure the experts out there can improve upon this, but here are the basics …

    On the Server

    1a. Add a new OperationContract to your Interface (eg. IService.cs)

    [OperationContract]
    string UploadBinaryFile(byte[] aByteArray);
    

    1b. Insert into SQL Server table, in your contract Implementation (eg. Service.cs)

    public string UploadBinaryFile(byte[] aByteArray)
    {
        try
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = MyConnectionString; // from saved connection string
            conn.Open();
            using (SqlCommand cmd = new SqlCommand("INSERT INTO MyTestTable(BinaryFile) VALUES (@binaryfile)", conn))
            {
                cmd.Parameters.Add("@binaryfile", SqlDbType.VarBinary, -1).Value = aByteArray;
                cmd.ExecuteNonQuery();
            }
    
            return "1"; // to me, this indicates success
        }
        catch (Exception ex)
        {
            return "0: " + ex.Message; // return an error indicator + ex.message
        }
    }
    

    On the Client

    2a. Use the OpenFileDialog component to browse for files on your filesystem using the standard dialogue box that’s used by most Windows applications.

    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        txtUploadFilePath.Text = openFileDialog1.FileName;
    }
    

    2b. Load the file’s contents into a byte array

    var byte[] BinaryFile = System.IO.File.ReadAllBytes(txtUploadFilePath.Text);
    

    2c. Call your WCF contract, passing in the byte array

    string UploadResponse = client.UploadBinaryFile(BinaryFile);
    

    It’s working… YAY 🙂

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

Sidebar

Related Questions

Ok - I have a WCF Service which reads an excel file from a
I'm trying to read an excel file from C# using COM, and can get
Is it possible to pass a delegate to a WCF remote object from the
I am using SSIS to do data transformation from excel to OLEDB SQL. I
This code exports data into a csv file, which is opened within Excel. When
this code reads contents of cell of excel file into a string String theCell_00=rs.getCell(j,i).getContents();
I have 3D WPF visual that I want to pass into an Excel cell
I'm trying to read excel file and pass all the data to DB. I
Pass a []byte into a template as the body of a message post on
I am trying to pass parameters from Visual Studio using VB.net to a Crystal

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.