G
Guest
Good Day All,
Sorry if I am posting in the wrong forum, hopefully someone will be able to
push me in the right direction. What I am trying to accomplish is allowing a
client to upload an Excel file and then I need to access the Excel file
without saving the file directly to the server. What I am eventually going to
do is save the Excel data into a database. Here is a sample of what I am
trying to do, and I may be way off track here.
if ( filMetricFile.PostedFile != null )
{
// Get a reference to PostedFile object
HttpPostedFile _metricFile = filMetricFile.PostedFile;
// Get size of uploaded file
int nFileLen = _metricFile.ContentLength;
// make sure the size of the file is > 0
if( nFileLen > 0 )
{
// Allocate a buffer for reading of the file
byte[] _metricData = new byte[nFileLen];
// Read uploaded file from the Stream
_metricFile.InputStream.Read(_metricData, 0, nFileLen);
OleDbConnection ExcelConnection = new OleDbConnection(
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ _metricFile + ";Extended Properties=Excel 8.0;");
ExcelConnection.Open();
//Do something with the ExcelConnection
}
}
And of course I am sure you can see I am missing something. When I try the
ExcelConnection.Open() I will get a an error stating that the object is read
only.
So I’m not sure if what I am doing is even possible, but any help would be
greatly appreciated. I just want to process the Excel file while in memory
and not have to save the file directly to the server first.
Thanks,
Jake
Sorry if I am posting in the wrong forum, hopefully someone will be able to
push me in the right direction. What I am trying to accomplish is allowing a
client to upload an Excel file and then I need to access the Excel file
without saving the file directly to the server. What I am eventually going to
do is save the Excel data into a database. Here is a sample of what I am
trying to do, and I may be way off track here.
if ( filMetricFile.PostedFile != null )
{
// Get a reference to PostedFile object
HttpPostedFile _metricFile = filMetricFile.PostedFile;
// Get size of uploaded file
int nFileLen = _metricFile.ContentLength;
// make sure the size of the file is > 0
if( nFileLen > 0 )
{
// Allocate a buffer for reading of the file
byte[] _metricData = new byte[nFileLen];
// Read uploaded file from the Stream
_metricFile.InputStream.Read(_metricData, 0, nFileLen);
OleDbConnection ExcelConnection = new OleDbConnection(
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ _metricFile + ";Extended Properties=Excel 8.0;");
ExcelConnection.Open();
//Do something with the ExcelConnection
}
}
And of course I am sure you can see I am missing something. When I try the
ExcelConnection.Open() I will get a an error stating that the object is read
only.
So I’m not sure if what I am doing is even possible, but any help would be
greatly appreciated. I just want to process the Excel file while in memory
and not have to save the file directly to the server first.
Thanks,
Jake