跪求。 office2007 .docx格式保存进数据库后读取出错!
先放出我的代码。
OpenFileDialog openFileDialog1 = new OpenFileDialog();
string filNm;
string mingc;
openFileDialog1.Multiselect = false;
openFileDialog1.Filter = "MS-Word Files (*.doc,*.dot,*.docx) | *.doc;*.dot;*.docx";
if (filNm == "")
{
MessageBox.Show("Please wait while the document is being displayed");
return;
}
FileStream fs = File.OpenRead(textBox2.Text);
byte[] content = new byte[fs.Length];
fs.Read(content, 0, content.Length);
fs.Close();
----------------------将*.docx文档转换为二进制数据---------------------
----连接数据库代码省略----
/// <summary>
/// 直接执行SQL语句(二进制流)
/// </summary>
public int RunProc(byte[] content, string mingcheng,string zm)
{
this.Open();
string sql = "INSERT INTO WDGL (WDIM,WDName,zm) VALUES (@Photos, @name,@zm)";
SqlCommand comm = new SqlCommand(sql, con);
comm.Parameters.Add("@Photos", SqlDbType.Image).Value = content;
comm.Parameters.Add("@name", SqlDbType.NVarChar).Value = mingcheng;
comm.Parameters.Add("@zm", SqlDbType.NVarChar).Value = zm;
comm.ExecuteNonQuery();
this.Close();
this.Dispose();
return 1;
}
--------------------------------利用如上代码 将二进制数据 保存到数据库中 -----------------------
private void ShowImage()
{
string str1 = System.Windows.Forms.Application.ExecutablePath //获取exe文件所在路径
AppDomain.CurrentDomain.BaseDirectory
string str5 = Application.StartupPath;
//取得路径
//string path = str1.ToLower().Replace("windowsapplication1.exe", "test.doc");
byte[] b = baseinfo.wendang(id);
if (b == null)
{
MessageBox.Show("文档无法读取!");
}
else
{
if (b.Length > 0)
{
int ArraySize = new int();
ArraySize = b.GetUpperBound(0);
FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(b, 0, ArraySize);
fs.Close();
string film = str5 + "\\test.doc";
try
{
objWinWordControl.CloseControl();
}
catch { }
finally
{
objWinWordControl.document = null;
WinWordControl.WinWordControl.wd = null;
WinWordControl.WinWordControl.wordWnd = 0;
}
try
{
objWinWordControl.LoadDocument(film);
}
catch (Exception ex) { String err = ex.Message; }
}
}
}
-------------------如上为恢复二进制的方法,再利用winWordControl显示恢复的.docx文件,失败------------------------------
但是用以上方法存取.doc文件没有问题。请各位高手大哥帮帮忙!!!!!