【问题标题】:Open a pdf file using c# with textbox使用带有文本框的 c# 打开一个 pdf 文件
【发布时间】:2018-02-13 16:49:44
【问题描述】:

我想用 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);
        }
    }

但我想打开一个名称为 o 的 pdf 文件,文件位于文本框或/和 sql 表中,如下所示:

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

谢谢

【问题讨论】:

  • 你试过使用TextBox的Text属性吗?

标签: c# pdf


【解决方案1】:

解决了这个问题:

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);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-21
    相关资源
    最近更新 更多