1

I'm building an application that takes as an input data stored in an Excel sheet. I want the user to be able to select the file they want to load data from, have the application connect to and read from the Excel file stored on the client's machine, and close the connection. Can I do this without uploading the Excel file to the server? I'm able to do everything except for selecting the file using a filedialog box and passing the path & file name to the procedure that connects to the Excel file and processes. I've tried using the file input control but I'm unable to pass the path & file name to the connection string. Any suggestions as to what other routes I might take?

EDIT:

The application essentially takes user input, either via single inputs into textboxes on the page or a bulk upload via an Excel spreadsheet, processes the inputs and spits out a report in Excel format. The only thing displayed on the page are the loaded inputs (via the 2 methods just described) in a listbox that the user can either add or remove additional items.

StephenT
  • 475
  • 5
  • 25
  • I've given a short answer. If you provide more details regarding your scenario, we might be able to help further. What is the basic format of the data? Simple rows and columns? Is it a simple "rectangular" format, or is it more complex? – bopapa_1979 Oct 18 '13 at 20:41
  • It's a very simple rectangular format with 2 columns. Also, security isn't an issue here as the application is only available to internal users via intranet. Thanks Eric – StephenT Oct 18 '13 at 20:54
  • 1
    I'm a little lost reading your question. Should have asked for more info before posting an answer. Are you wanting to process the data on the server, display it on the client, or what? If you just want to display it, an IFrame can work... Look here: http://stackoverflow.com/questions/9678127/how-to-display-excel-sheet-in-html-page. If you want to handle it on the server, you should upload it. Period. If you cannot for some reason, I'm not sure what else to tell you. – bopapa_1979 Oct 21 '13 at 15:01
  • 1
    FYI, since you appear to be new, this is unsolicited advice and NOT intended to be condescending or rude. When posting a question, the more info the better: http://tinyurl.com/so-hints – bopapa_1979 Oct 21 '13 at 15:03
  • Apologies Eric. I've updated my original query with some additional info on how the application is intended to work. – StephenT Oct 21 '13 at 16:04
  • 1
    Thanks for the update. If you are creating the report on the server, you'll have to upload the file. If you are creating the report on the client, you'll have to upload the file and pass the relevant data back to the client. If you don't want to do a full-page postback, send back a json object you can iterate over via JavaScript on the client. Cheers! Do you have any further questions? – bopapa_1979 Oct 21 '13 at 19:55
  • Report is being created on the server so I used option A. Thanks for the help Eric! – StephenT Oct 22 '13 at 14:26
  • By option 'A,' you mean displaying the information in an IFrame? Let me know and I will update my answer. That way it will be correct and you can accept it. That will be more helpful to others than reading our long conversation in these comments :) – bopapa_1979 Oct 22 '13 at 14:37
  • Sorry, I meant uploading the Excel file to the server, saving it under a randomly generated name (using Guid.NewGuid().ToString()) in a temporary folder, adding the data from the Excel file to the listbox object (is that an IFrame?) on the page and deleting the uploaded Excel file. – StephenT Oct 22 '13 at 20:29
  • I updated my answer based on your final round of comments. If you care to accept it, I would be grateful. If not, that's OK too. – bopapa_1979 Oct 22 '13 at 21:51

1 Answers1

2

The short answer is "Only with an ActiveX control in IE unless you write your own plugin for another browser." My opinion is, "you shouldn't."

There is a good discussion already on Stack Overflow: How to read an excel file contents on client side?

The long answer, given the rest of the information you have provided, is that I would recommend the following:

1) Upload the spreadsheet to the server. 2) Extract the data on the server. 3) Return the data to the client in whatever form suits your situation. 4) Clean the original file on the server.

Some further recommendations for you, since you provided so much detail in your comments:

  • Rather than using a GUID to generate your server-side filename, use a timestamp in the format YYYY-MM-DD-HH-MM-SS-Ticks followed by the original filename.
  • Instead of deleting the data files immediately, each time you add a file, remove any files older than N days.

This way if you have any issues processing your files in the future, you'll be able to retrieve the uploaded file to your development environment and debug it there. Assuming the data isn't personal information or sensitive in some other way, of course.

Cheers!

Community
  • 1
  • 1
bopapa_1979
  • 8,949
  • 10
  • 51
  • 76