.Net实现Word文档及导出 ...文本正由另一进程使用,因此该进程无法访问该文件

参考网址:

http://www.jb51.net/article/25062.htm(实用性)

http://wenku.baidu.com/link?url=44O7Dua49DrZ-PF2QU70Aobp8D8cOTBWXtYxfxAFwzbjJswHulXZfiOlhFmXsnJH1MHpy83EA8Gt-yaNVAADfuhhZHzGRqourd30ig5V3ka

http://www.csharpwin.com/dotnetspace/12470r7724.shtml

http://bbs.csdn.net/topics/220001707(各文本加入)

WORD文档保存后,获取并现在已保存文档。

   string path = AppDomain.CurrentDomain.BaseDirectory + ("UpFiles\") + fileName;
   return File(new FileStream(path, FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite), "image/jpeg jpeg jpg jpe", fileName);

此处加入:System.IO.FileAccess.Read, FileShare.ReadWrite  文档流只读,文档共享读写操作。可避免如下错误提示

=================

        /// <summary>
        /// 新建Word文档
        /// </summary>
        /// <param name="path">文件路径</param>
        /// <param name="strContent">文件内容</param>
        public void CreateWordFile(string path, string strContent)
        {

            MSWord.Application wordApp;
            //C#创建Word文档之word应用程序  

            MSWord.Document wordDoc;//word文档  


            wordApp = new MSWord.Application();

            if (File.Exists(path))
            {

                File.Delete(path);

            }

            object filePath = path;
            Object nothing = Missing.Value;

            wordDoc = wordApp.Documents.Add(
            ref nothing, ref nothing, ref nothing, ref nothing);

            wordApp.Visible = false;

            wordDoc.Paragraphs.Last.Range.Text = strContent;

            object format = MSWord.WdSaveFormat.wdFormatDocumentDefault;

            wordDoc.SaveAs(ref filePath, ref format,
            ref nothing, ref nothing, ref nothing,
            ref nothing, ref nothing,

             ref nothing, ref nothing, ref nothing,
            ref nothing, ref nothing, ref nothing,

            ref nothing, ref nothing, ref nothing);

            wordDoc.Close(ref nothing, ref nothing, ref nothing);

            wordApp.Quit(ref nothing, ref nothing, ref nothing);
        }