Doubt when generating a .doc file with C #

1

The method below downloads the document that is generated dynamically, however when the file is opened it shows a file conversion option, leaving the Unicode (UTF-8) checked by default.

What do you do to not show this message?

    public static void gerarRelatorioAtoDoc(string texto)
    {
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Charset = "";
        HttpContext.Current.Response.ContentType = "application/msword";

        String strNomeArquiv = "RelAtoGerado" + DateTime.Now.ToShortDateString().ToString() + ".doc";
        HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strNomeArquiv);

        StringBuilder strHTMLContent = new StringBuilder();
        strHTMLContent.Append(texto);
        HttpContext.Current.Response.Write(strHTMLContent);
        HttpContext.Current.Response.End();
        HttpContext.Current.Response.Flush();
    }
    
asked by anonymous 15.01.2015 / 19:53

1 answer

2

With the help of gypsy-morrison-mendez and using the library DocX v1.0.0.14 solved the problem as follows:

    public static void gerarRelatorioAtoDoc(string texto)
    {
        string fileName = @"C:\Users\seu-nome\DocXExample.docx";
        var doc = DocX.Create(fileName, DocumentTypes.Document);
        doc.InsertParagraph(texto);
        doc.Save();
        Process.Start("WINWORD.EXE", fileName);
    }

The text parameter can be anything, in the case above it gets the contents of a Textbox .

    
16.01.2015 / 13:30