Guest User

Guest User

  • Tech Writer
  • 529
  • 41.2k

C# PDF Windows Application Read Direct

Feb 26 2022 5:35 AM

\\Run .exe file error after install software Need Help

i will attach this error file 

FileName;- Error Code Fix it Please

 \\ Here is C# Code

private void btnOpen_Click(object sender, EventArgs e)
{
    var selectedRow = bunifuDataGridView1.SelectedRows;
    foreach(var row in selectedRow)
    {
        int id = (int)((DataGridViewRow)row).Cells[0].Value;
      
        OpenFile(id);
    }
}
private void OpenFile(int id)
{
    DataBase data = new DataBase();
    string query = "SELECT Document,Name,FileName,Extension From tblRegister Where id=@id";
    SqlDataAdapter sda = new SqlDataAdapter(query, data.getDatabaseConnection());
    sda.SelectCommand.Parameters.Add("@id", SqlDbType.Int).Value = id;
    data.openDBConnection();
    var reader = sda.SelectCommand.ExecuteReader();
    if (reader.Read())
    {
        var name = reader["FileName"].ToString();
        var datas = (byte[])reader["Document"];
        var extn = reader["Extension"].ToString();
        var newFileName = name.Replace(extn, DateTime.Now.ToString("ddMMyyyhhmmss")) + extn;        
        File.WriteAllBytes(newFileName, datas);
        System.Diagnostics.Process.Start(newFileName);
    }
}

i will try to read pdf file from sql server and i will try direct open pdf any browse or AcbordReader


Attachment: Error_Code.rar

Answers (2)