Click here to Skip to main content
14,883,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have displayed word document in HTML format in .aspx page, but the embedded HTML file replaces "space" as "?" special character.

How can I remove the special character?

Here is the code I used for your reference:

C#
try
            {
                //To check the file extension if it is word document or something else
                string strFileName = fUpload.FileName;
                string[] strSep = fUpload.FileName.Split('.');
                int arrLength = strSep.Length - 1;
                string strExt = strSep[arrLength].ToString().ToUpper();
                //Save the uploaded file to the folder
                strPathToUpload = Server.MapPath("Uploaded");
                //Map-path to the folder where html to be saved
                strPathToConvert = Server.MapPath("WordToHtml");
                object FileName = strPathToUpload + "\\" + fUpload.FileName;
                object FileToSave = strPathToConvert + "\\" + fUpload.FileName + ".htm";
                if (strExt.ToUpper().Equals("DOC"))
                {
                    fUpload.SaveAs(strPathToUpload + "\\" + fUpload.FileName);
                    lblMessage.Text = "File uploaded successfully";
                    //open the file internally in word. In the method all the parameters should be passed by object reference
                    objWord.Documents.Open(ref FileName, ref readOnly, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref  missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing,
                    ref missing, ref missing);
                    //Do the background activity
                    objWord.Visible = false;
                    Microsoft.Office.Interop.Word.Document oDoc = objWord.ActiveDocument;
                    oDoc.SaveAs(ref FileToSave, ref fltDocFormat, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing);
                    lblMessage.Text = fUpload.FileName + " converted to HTML successfully";

                }
                else
                {
                    lblMessage.Text = "Invalid file selected!";
                }
                //Close/quit word
                objWord.Quit(ref missing, ref missing, ref missing);

                string[] strHtml = System.IO.Directory.GetFiles(strPathToConvert);
                Response.ContentType = "text/html";
                Response.WriteFile(strHtml[0]);

Can you please help me out in this.

Thanks in advance.
Posted
v2

1 solution

Try adding charset=utf-8 to ContentType.
C#
Response.ContentType = "text/html;charset=utf-8";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900