Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用SoftArtisan';让WordWriter合并文档_C#_Content Type - Fatal编程技术网

C# 使用SoftArtisan';让WordWriter合并文档

C# 使用SoftArtisan';让WordWriter合并文档,c#,content-type,C#,Content Type,这是我的文件模型: public class File { public int Id { get; set; } public string fileName { get; set; } public byte[] fileContent { get; set; } public string contentType { get; set; } public long fileSize { get

这是我的文件模型:


    public class File
    {
        public int Id { get; set; }
        public string fileName { get; set; }
        public byte[] fileContent { get; set; }
        public string contentType { get; set; }
        public long fileSize { get; set; }
    }
内容类型为:application/msword

List<File> liste = new List<File>();
我得到以下例外情况:

此文档不是兼容的Word文档。WordWriter支持 使用Word 97、Word 2000、Word XP和Word 2003创建的文档。 System.IO.IOException:无法读取整个标头-读取1字节; 应为512字节

你知道如何设置流的内容类型吗?
我无法将文件写入磁盘并对其进行设置。

尝试使用.doc扩展名而不是.docx保存文档,然后tryDocument将保持流状态,因此不设置扩展名。从模型的字节[]读取流。

    foreach (var doc in liste)
    {
    using (MemoryStream ms = new MemoryStream())
    {
        ms.Read(doc.fileContent, 0, Convert.ToInt32(doc.fileSize));
        Document documentToAppend = WA.Open(ms);
        baseDocument.Append(documentToAppend);
    }
    }