使用带文本框的c#打开pdf文件

时间:2018-02-13 16:49:45

标签: c# pdf

我想在C#中打开一个特定的pdf文件。 它正在使用:

private void Button1_Click(object sender, EventArgs e)
{
string filename = "instructions.pdf";
System.Diagnostics.Process.Start(filename);
}

并且用这个:

 private void button1_Click(object sender, EventArgs e)
    {

        OpenFileDialog open = new OpenFileDialog();
        open.Title = "Open";
        open.Filter = "pdf files (*.pdf) |*.pdf;";
        open.InitialDirectory = @"C:\temp";

        try
        {
            if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                axAcroPDF1.LoadFile(open.FileName);
            }
        }
        catch (ArgumentException ex)
        {
            MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

但是我想打开一个带有de name o文件的pdf文件在文本框或/和sql表中是这样的:

private void Button1_Click(object sender, EventArgs e)
    {
    string filename = "TEXTBOX1.pdf";
    System.Diagnostics.Process.Start(filename);
    }

由于

1 个答案:

答案 0 :(得分:0)

解决了这个问题:

private void button1_Click(object sender, EventArgs e)
    {
        string filename = textBox1.Text + ".pdf";
        string path = @"c:\temp\";
        string pathfilename = string.Concat(path,filename);
        System.Diagnostics.Process.Start(pathfilename);
    }