You must Sign In to post a response.
  • Category: ASP.NET

    Word Document download issue

    Hi All,

    I formatted text in word document as per client requirement and saved the file as web page(.htm) format.
    Dot net web application will read the content dynamically from DB /static content and placed it into htm file, finally will create word document.
    Issue:

    Once downloaded the word document and when I tried to open I got below error message.
    "Problems came up following areas during the load.
    Missing file : c:\users\ravi\test\test3files\header.htm "


    I implemented below logic for download document.

    bool forceDownload = true;
    string ext = Path.GetExtension(fileName);
    string filetype = "";
    if (ext != null)
    {
    switch (ext.ToLower())
    {
    case ".htm":
    case ".html":
    filetype = "text/HTML";
    break;

    case ".txt":
    filetype = "text/plain";
    break;

    case ".doc":
    case ".rtf":
    case ".docx":
    filetype = "Application/msword";
    break;
    default:
    filetype = "application/octet-stream";
    break;
    }
    }
    if (forceDownload)
    {
    Response.AppendHeader("content-disposition",
    "attachment; filename=" + fileName);
    }
    if (filetype != "")
    Response.ContentType = filetype;
    Response.WriteFile(filePath);
    Response.End();
    Response.Close();
    File.Delete(fileName);

    Please let me know if you have solution / steps to resolve the issue. Thanks in advance.

    Regards,
    Ravi
  • #769232
    Do you have a header and footer in word document ? as per the standard of word and html, header and footer can not be exported to word application.
    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #769237
    Hi Prasad,

    There is no header and footer in the word document. (Only text )

    Regards,
    Ravi


Sign In to post your comments