Ravi

Ravi

  • NA
  • 10
  • 651

Word document download issue

May 29 2017 12:20 AM

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 wrote below logic for downlaod 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);

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

Regards,

Ravi


Answers (1)