Office.Interop.Word Saveas表示无效的文件名



使用microsoft.interop.word我尝试保存一个word文件(docx(。在大多数情况下,它可以节省良好,但偶尔却没有。而且我无法弄清楚是什么是什么原因导致错误。

基于当前相关数据生成文件和路径。在此(失败的(示例中

g: red group varme tilbud_tilbudsprogram 108472_test-customer a_s projektafregning kun til til he pro kolding 108472_test-customer a_s projektafregning kun til til he pro kolding _201802062146.docx

错误消息是" 无效的文件名 ..."

例外是:

在Microsoft.office.interop.word.documentClass.saveas2(object& 文件名,对象&fileformat,object&锁定,对象&密码, 对象&addtorecentfiles,object&writePassword,Object& ReadOnlyRecmunded,Object&EmbedtruetypeFonts,Object& SavenativePictureFormat,Object&saveformsdata,object& SaveAsaocetter,Object&编码,对象&Insertline Breaks,Object& 允许提示,对象&线路,对象&addBidimarks,对象& compatibilitymode(at quot.word.word.openandshow(字符串Mergefile, 字符串馆表(在f: dbconsult kunder danfoss Quotation 2017 Danfoss 引号 danfoss引号 class wordmerge.cs:行333

行333是worddoc.saveas((行。代码的那一部分看起来像这样:

wordDoc.Activate();
wordApp.Visible = true;
wordApp.Activate();
try
    {
        wordDoc.SaveAs(_fullpath);
    }
catch (Exception ex)
{
    using (StreamWriter sw = File.CreateText(_fullpath))
    {
        sw.WriteLine("Hey");
    }
    Helper.Log(ex.Message, ex.StackTrace, "WordMerge.OpenAndShow()");
    return false;
}

我的捕获量中的"使用"部分是用于测试。如果我使用StreamWriter ,则创建了该文件,因为它应该。因此,我认为这是Saveas((Mehtod的缺陷。这个结论似乎是正确的吗?如果是这样:有什么线索该怎么办?

最好的问候莫滕

通过替换空间字符来解决:替换("," - "(。

我无法确切地弄清楚这是什么触发的,因为我有很多成功的保存而没有发生错误 - 以及我的空间。

此外,所有失败的保存与StreamWriter都很好地搭配。因此,这似乎是Word.interop中的一些内部缺陷。

br

最新更新