0
我正在嘗試將本地文件保存到內存流中,但我遇到了讓我的代碼工作的問題。我試圖通過將文件保存到內存流來完成此操作,但沒有運氣。 Word.Document只允許對象類型通過其方法傳遞,因此我無法使用Word.Document.saveas方法保存文檔。以下是代碼:將word.doc保存到內存流中
string getAttachment(string path)
{
string docname = path;
string[] sl = docname.Split('.');
string name = sl[0];
object missing = Type.Missing;
string doc = @"...\articles\" + name + ".docx";
object source = doc;
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocumentDefault;
//Word.Document worddoc = new Word.Document();
MemoryStream outStream = new MemoryStream();
FileStream outdoc = new FileStream();
object stream;
worddoc.SaveAs(outdoc, ref format, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing);
outStream = stream.ToString();
byte[] wordbytes = outStream.ToArray();
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(wordbytes);
return base64String;
}
做這個問題的答案可以幫助您 http://stackoverflow.com/?問題/ 1313247/how-do-i-read-a-word-doc-using-the-streamreader – 2012-01-04 10:25:08
不,我試圖將word.doc保存到內存流中,就像將圖像保存到內存流中一樣 – WorkerBee 2012-01-04 12:57:54