Read data file on client fails

  • Thread starter Thread starter Johnny
  • Start date Start date
J

Johnny

Hi all:

I have an ASP.NET form that reads an Excel file and populates a datagrid. If
I load the form in IE on the server, and select a local file, the code works
fine. However if I load the form in IE from a client
(http://server/readexcel.aspx) and try to read a local Excel file, the file
cannot be opened.

I imagine it's some kind of a security problem in sending the Excel data
back to the web server, but I am not sure.

Does anyone know how to fix this?

Thanks for any and all help.
 
Johnny said:
I have an ASP.NET form that reads an Excel file and populates a datagrid. If
I load the form in IE on the server, and select a local file, the code works
fine. However if I load the form in IE from a client
(http://server/readexcel.aspx) and try to read a local Excel file, the file
cannot be opened.

I imagine it's some kind of a security problem in sending the Excel data
back to the web server, but I am not sure.

Does anyone know how to fix this?

Have you tried saving the file from the server instead of opening it,
and then comparing it with the original? It's possible that the code
you're using to serve the file is failing - although we'd have to see
that code to know...
 
Hi John:

Thanks for the note but I am not sure what you mean. In each case the file
is on the machine I am loading the ASPX page from. So on the server the file
is at c:\temp\test.xls, and if I open IE on the server and type
http://server/readexcel.aspx, it works fine. If I then go to a client
machine, and again the file is local on the machine at c:\temp\test.xls, and
I open IE on the client and type http://server/readexcel.aspx, the operation
fails.
 
Johnny said:
Thanks for the note but I am not sure what you mean. In each case the file
is on the machine I am loading the ASPX page from. So on the server the file
is at c:\temp\test.xls, and if I open IE on the server and type
http://server/readexcel.aspx, it works fine. If I then go to a client
machine, and again the file is local on the machine at c:\temp\test.xls, and
I open IE on the client and type http://server/readexcel.aspx, the operation
fails.

So what are you expecting the server to do? It can't read the local
file - that would be a hideous security problem.

What does readexcel.aspx actually try to do?
 
Hi Jon:

Shoot. :(

Readexcel.aspx is a very simple ASPX page with a Datagrid. All the page does
is read the Excel file and bind the data to the grid:

exConn1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
exConn1 += File1.PostedFile.FileName.ToString();
exConn1 += ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";

//==========================================================
//==========================================================
try
{
conn1 = new System.Data.OleDb.OleDbConnection(exConn1);
conn1.Open();
fileOpen = true;
}
catch (Exception ex)
{
Console.Writeline( "Open error " + ex.ToString() );
}

if ( fileOpen )
{
try
{
cmd1 = new System.Data.OleDb.OleDbCommand("Select * From [Sheet1$]",
conn1);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = cmd1;
DataSet objDataset1 = new DataSet();
objAdapter1.Fill(objDataset1, "XLData");
GridView1.DataSource = objDataset1.Tables[0].DefaultView;
GridView1.DataBind();
}
catch (Exception readEx)
{
Console.Writeline( "Read error " + readEx.ToString() );
}
}

Is there a way to read the local file using an HTTP stream or something?
 
Johnny said:
Shoot. :(

Readexcel.aspx is a very simple ASPX page with a Datagrid. All the page does
is read the Excel file and bind the data to the grid:

exConn1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
exConn1 += File1.PostedFile.FileName.ToString();
exConn1 += ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";

And what is File1 here? That's the key, I suspect...

If you've got a file upload control (e.g. the kind used to upload
attachments in web mail applications) then you can't just refer to the
filename - that's the local filename on the PC the browser is running
on. You need to extract the *contents* of the file from the POST data,
save it on the server, and *then* you can start to use it.

Currently, you're trying to open a database connection on the server,
referring to a file which only exists on the client.
 
Hi Jon:

Thanks and what you've said makes sense, it is a HTML file input control. Do
you know where I could see some documentation on how to do what you
described below?
 
Johnny said:
Thanks and what you've said makes sense, it is a HTML file input control. Do
you know where I could see some documentation on how to do what you
described below?

I remember implementing it a while ago for a test app, but it didn't do
the full works. A google search should be able to help you though.
 
Thanks for your help Jon...a Live search (Google, what's Google?!?! :))
returned an excellent example on the Code Project. Without your help I
wouldn't have known what I was looking for.
 
Back
Top