How to organize a file downloading from server database and open it on the client machine?
my code works only when the page is opened on the server:
OracleCommand oracleCom = new OracleCommand();
oracleCom.Connection = oraConnect;
oracleCom.CommandText = "Select m_content, f_extension From " + Session["tableNameIns"] +
" where i_id = " + rowData;
OracleDataAdapter adapter = new OracleDataAdapter();
DataTable tableD = new DataTable();
tableD.Locale = System.Globalization.CultureInfo.InvariantCulture;
adapter.SelectCommand = oracleCom;
adapter.Fill(tableD);
string FileName = Path.GetTempPath();
FileName += "tempfile" + tableD.Rows[0][1];
byte[] file = new byte[0];
file = (byte[])tableD.Rows[0][0];
FileStream fs = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(file, 0, file.GetUpperBound(0) + 1);
fs.Close();
System.Diagnostics.Process.Start(FileName);
This is just not possible in a web application.
If you want to do this, write a windows application.
Security restrictions on a browser will not allow you to download and directly run an exe from a browser.
You can send the exe in the response, where the user saves and runs it manually.
In your current setting, the exe is still being written and run on the server, regardless of if the request comes from.
Just a side note, its a lot easier to use
WriteAllBytesto write byte arrays to files.You don’t have to worry about locks and disposing objects that way.