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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:25:36+00:00 2026-05-21T19:25:36+00:00

Ok – I have a WCF Service which reads an excel file from a

  • 0

Ok – I have a WCF Service which reads an excel file from a certain location and strips the data into an object. What I need is the ability to allow users of my program to Upload an excel sheet to the file location that my Service uses.

Alternitivley I could pass the Uploaded excel sheet to the service directly.

Can anyone help with this. My service code is:

    public List<ImportFile> ImportExcelData(string FileName)
    {
        //string dataSource = Location + FileName;
        string dataSource = Location;
        string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + dataSource.ToString() + ";Extended Properties=Excel 8.0;";
        var con = new OleDbConnection(conStr);
        con.Open();

        var data = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
        var sheetName = data.Rows[0]["TABLE_NAME"].ToString();

        OleDbCommand cmd = new OleDbCommand("SELECT * FROM [" + sheetName + "] WHERE Status = '4'", con);
        OleDbDataAdapter oleda = new OleDbDataAdapter();
        oleda.SelectCommand = cmd;

        DataSet ds = new DataSet();
        oleda.Fill(ds, "Employees");
        DataTable dt = ds.Tables[0];

        var _impFiles = new List<ImportFile>();
        foreach (DataRow row in dt.Rows)
        {
            var _import = new ImportFile();

            _import.PurchaseOrder = row[4].ToString();

            try
            {
                var ord = row[8].ToString();
                DateTime dati = Convert.ToDateTime(ord);
                _import.ShipDate = dati;
            }
            catch (Exception)
            {
                _import.ShipDate = null;
            }


            ImportFile additionalData = new ImportFile();
            additionalData = GetAdditionalData(_import.PurchaseOrder);


            _import.NavOrderNo = additionalData.NavOrderNo;
            _import.IsInstall = additionalData.IsInstall;
            _import.SalesOrderId = additionalData.SalesOrderId;
            _import.ActivityID =  additionalData.ActivityID;
            _import.Subject =  additionalData.Subject ;

            _import.IsMatched = (_import.ShipDate != null & _import.NavOrderNo != "" & _import.NavOrderNo != null & _import.ShipDate > DateTime.Parse("01/01/1999") ? true : false);

            _import.UpdatedShipToField = false;
            _import.UpdatedShipToFieldFailed = false;
            _import.CreateNote = false;
            _import.CreateNoteFailed = false;
            _import.CompleteTask = false;
            _import.CompleteTaskFailed = false;
            _import.FullyCompleted = 0;
            _import.NotCompleted = false;
            _impFiles.Add(_import);

        }


        oleda.Dispose();
        con.Close();
        //File.Delete(dataSource);

        return _impFiles;

        } 
  • 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-21T19:25:37+00:00Added an answer on May 21, 2026 at 7:25 pm

    You will want to modify your service to accept a Stream instead of a filename, then you can save if off to a file (or parse it directly from the Stream, although I don’t know how to do that).

    Then in your Silverlight app you could do something like this:

    private void Button_Click(object sender, RoutedEventArgs ev)
    {
        var dialog = new OpenFileDialog();
        dialog.Filter = "Excel Files (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm|All Files (*.*)|*.*";
        if (dialog.ShowDialog() == true)
        {
            var fileStream = dialog.File.OpenRead();
            var proxy = new WcfService();
            proxy.ImportExcelDataCompleted += (s, e) =>
            {
                 MessageBox.Show("Import Data is at e.Result");
                 // don't forget to close the stream
                 fileStream.Close();
            };
            proxy.ImportExcelDataAsync(fileStream);
        }
    }
    

    You could also have your WCF service accept a byte[] and do something like this.

    private void Button_Click(object sender, RoutedEventArgs ev)
    {
        var dialog = new OpenFileDialog();
        dialog.Filter = "Excel Files (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm|All Files (*.*)|*.*";
        if (dialog.ShowDialog() == true)
        {
            var length = dialog.File.Length;
            var fileContents = new byte[length];
            using (var fileStream = dialog.File.OpenRead())
            {
                if (length > Int32.MaxValue)
                {
                    throw new Exception("Are you sure you want to load > 2GB into memory.  There may be better options");
                }
                fileStream.Read(fileContents, 0, (int)length);
            }
            var proxy = new WcfService();
            proxy.ImportExcelDataCompleted += (s, e) =>
                                                    {
                                                        MessageBox.Show("Import Data is at e.Result");
                                                        // no need to close any streams this way
                                                    };
            proxy.ImportExcelDataAsync(fileContents);
        }
    }
    

    Update

    Your service could look like this:

    public List<ImportFile> ImportExcelData(Stream uploadedFile)
    {
        var tempFile = HttpContext.Current.Server.MapPath("~/uploadedFiles/" + Path.GetRandomFileName());
        try
        {
            using (var tempStream = File.OpenWrite(tempFile))
            {
                uploadedFile.CopyTo(tempStream);
            }
    
            //string dataSource = Location + FileName;
            string dataSource = tempFile;
            string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + dataSource.ToString() +
                            ";Extended Properties=Excel 8.0;";
            var con = new OleDbConnection(conStr);
            con.Open();
        }
        finally
        {
            if (File.Exists(tempFile))
                File.Delete(tempFile);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a text file with the following data: Calculated Concentrations 30.55 73.48 298.25
I am currently scraping some data from the internet and converting into xml documents.
I have a simple restful service that transforms a JAXB-anntotated beans to response XML
I am getting the value from web service like &gt;&lt;&amp;&nbsp; etc. I want to
I am currently running into a problem where an element is coming back from
The problem with unsigned char. I am reading a PPM image file which has
Have a webpage that will be viewed by mainly IE users, so CSS3 is
So to start, I have an array of XML files. These files need to
i have this code: <?php $valid_ext = array(pdf, doc); $args = array( 'post_type' =>
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.