I have a problem with my Winforms Application. I have a database where the user can store files in. Doesnt matter if it is pdf, png etc...The user should see the file when double clicking on a row in a datagridview. I tried it like this:
private void DataGridCPU_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
sqlCon.Open();
SqlCommand cmd = sqlCon.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select Dok from cpuTabelle where Id='" + this.DataGridCPU.CurrentRow.Cells[0].Value.ToString() + "'";
var reader = cmd.ExecuteReader();
if (reader.Read())
{
var data = (byte[])reader["Dok"];
var newName = this.DataGridCPU.CurrentRow.Cells[0].Value.ToString()+"_"+ this.DataGridCPU.CurrentRow.Cells[1].Value.ToString();
File.WriteAllBytes(newName, data);
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = newName;
p.Start();
p.WaitForExit();
When I double click on a row now the exception in the title is thrown.
I also tried to add p.StartInfo.ErrorDialog=true;
before the p.Start();
line but then the Errorbox opens which says the file is not associated with an app for performing this action and a following exception: the operation was cancelled by the user.
I really dont know what to do...
Thanks for your help.