【发布时间】:2019-12-26 15:06:26
【问题描述】:
我有一个程序,我们用它来以 PDF 格式存储我们的文档。 目前,该程序能够根据用户输入生成 PDF,并自动生成包含交易 ID 的文件名。
但是,我还有一个上传功能,用户需要将签名(签名)文档上传到所选的交易 ID。此类在上传时不检查文档名称。
我的问题是,当 mssql 将文档存储在 blob 中时(例如 0x21349182361293871),mssql 是否也将文件名存储在该 blob 字符串中?
如果是,我如何在该 blob 中提取文件名,以便在下载文件时,我可以重新附加文件名,以便我可以继续让我的代码检查文件是否为 PDF。
目前这是我的下载代码:
private void Button1_Click(object sender, EventArgs e)
{
var LMTF2 = new LogToFile();
string appdb = "someconnstring";
tempfileName = Path.GetTempFileName();
string tempfileloc = tempfileName;
SNe = importID.Text.ToString();
cdoc2 = cDoc.SelectedValue.ToString();
using (SqlConnection sqlconnection = new SqlConnection(appdb))
{
sqlconnection.Open();
dLoad = new DataSet();
string selectQuery = "Select " + cdoc2 + " From StaffTrans Where TransID=" + SNe;
try
{
SqlCommand selectCommand = new SqlCommand(selectQuery, sqlconnection);
SqlDataReader reader = selectCommand.ExecuteReader();
if (reader.Read())
{
byte[] fileData = (byte[])reader[0];
// Write/Export File content into new text file
File.WriteAllBytes(tempfileloc, fileData);
}
}
catch (System.Exception ex)
{
MessageBox.Show("Cannot locate file! File doesn't exist or wrong transaction ID. Exception error : " + ex.Message);
LMTF2.LogMessageToFile("Cannot locate file! File doesn't exist or wrong transaction ID " + ex.Message);
}
try
{
//Open downloaded file
System.Diagnostics.Process.Start(tempfileloc);
}
catch (System.Exception ex)
{
MessageBox.Show("Cannot Open Downloaded File. File could be corrupted. : " + ex.Message);
LMTF2.LogMessageToFile("Cannot locate file! File doesn't exist or wrong transaction ID " + ex.Message);
}
}
}
我已经尝试添加
string extension = System.IO.Path.GetExtension(tempfileloc);
但这什么也没给我。
【问题讨论】:
-
does mssql also store the filename in that blob string?号 -
不,它没有,它只是保存内容而不知道它是什么
-
如果您需要存储额外的数据,例如文件名、扩展名、插入日期等,您需要在不同的列中这样做。
标签: c# sql-server pdf