首先,我将 Excel 文档转换为 Byte 并将它们存储在 SQL SERVER 2008 中
string[] TotalCount = Directory.GetFiles(FileDropLocation);
foreach (string item in TotalCount)
{
FileStream fs = new FileStream(item, FileMode.Open, FileAccess.Read);
string fileName = Path.GetFileName(item);
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
//insert the file into database
string strQuery = "insert into tblFiles(Name, ContentType, Data) values (@Name, @ContentType, @Data)";
SqlCommand cmd = new SqlCommand(strQuery);
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = fileName;
cmd.Parameters.Add("@ContentType", SqlDbType.VarChar).Value = contenttype;
cmd.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes;
InsertUpdateData(cmd);
lblMessage.ForeColor = System.Drawing.Color.Green;
lblMessage.Text = "File Uploaded Successfully";
}
其次,我想将其检索为 PDF 而不是 excel 并将其显示在我的 aspx 页面上。这可以做到吗?请在这部分寻求帮助。
提前致谢, HRG