我正在尝试将本地文件保存到内存流中,但是我遇到了使代码生效的问题。我尝试通过将文件保存到内存流来完成此操作,但没有运气。 Word.Document只允许通过其方法传递对象类型,因此我无法使用Word.Document.saveas方法保存文档。以下是代码:
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;
}