繁体   English   中英

使用FileStream从Adobe PDF阅读器保存所选PDF时如何解决我的错误?

[英]How to solve my error when using FileStream to save selected PDF from Adobe PDF reader?

我正在使用Adobe PDF Reader从计算机上查看扫描的纸张,并尝试将其保存到Windows窗体应用程序中的数据库中。

我使用打开文件对话框选择PDF文件,然后将其保存在数据库中。 我正在使用以下代码:

private void btnPDF_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                PDFViewer.src = ofd.FileName;
            }
        }
private void btnsave_Click(object sender, EventArgs e)
        {
            MemoryStream msins = new MemoryStream();
            MemoryStream msid = new MemoryStream();
            pictureInsurance.Image.Save(msins, pictureInsurance.Image.RawFormat);
            pictureIDIQAMA.Image.Save(msid, pictureIDIQAMA.Image.RawFormat);
            byte[] byteInsurance = msins.ToArray();
            byte[] byteId = msid.ToArray();
            FileStream fStream = File.OpenRead("C:\\myfile.pdf");
            byte[] Doccontents = new byte[fStream.Length];
            fStream.Read(Doccontents, 0, (int)fStream.Length);
            fStream.Close();

            if (update == 1)
            {
                patient.ADD_PATIENT(textName.Text,
                                Convert.ToInt32(textAge.Text),
                                textMobile.Text,
                                textEmail.Text, textaddress.Text,
                                Convert.ToInt32(combogender.SelectedValue),
                                textIDNO.Text,
                                Convert.ToInt32(comboNat.SelectedValue), 
                                byteInsurance,byteId,Doccontents);
                MessageBox.Show("Patient Added Successfully", "ADD PATIENT", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

当我使用固定路径时,将内容保存在数据库中:

FileStream fStream = File.OpenRead("C:\\myfile.pdf");

但是当我使用Adobe PDF Reader的名称保存选定的PDF文件时,它显示以下错误“ mscorlib.dll中发生了'System.ArgumentException类型的未处理的异常”

其他信息:不支持URI格式。”

这是有错误的代码:

FileStream fStream = File.OpenRead(PDFViewer.src);

并使用此修复路径进行保存,没有错误:

FileStream fStream = File.OpenRead("C:\\myfile.pdf");

这是我的void参数调用存储过程的零件代码,并且varbinary列正确吗?

public void ADD_PATIENT(string DocContent )
        {
            DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
            DAL.open();
            SqlParameter[] param = new SqlParameter[11];

            param[10] = new SqlParameter("@DocContent", SqlDbType.VarBinary);
            param[10].Value = DocContent;

            DAL.ExecuteCommand("ADD_PATIENT", param);
            DAL.close();

        }

保存所选文件而不是PDFViewer.src时需要做哪些代码更改,或者如何使用byte []方法和图像之类的内存流将PDF保存在SQL Server数据库中?

File.OpenRead()的参数需要一个字符串。 如果PDFViewer.src不是字符串类型,而是URI(或类似类型),那么您将遇到所提到的问题。 确保PDFViewer.src是一个字符串(包含有效的路径和文件名),或者如果可能的话,将其强制转换为字符串:

 FileStream fStream = File.OpenRead((PDFViewer.src).ToString());

要么

 FileStream fStream = File.OpenRead((string)PDFViewer.src);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM