Need immediate help RRS feed

  • Question

  • User-46109667 posted

    hi all,

    I am creating a word document dynamically using c#. it done using,

    StringBuilder strbulider = new StringBuilder();
    string strBody = string.Empty;
    strBody = @"<html xmlns:o='urn:schemas-microsoft-com:office:office' " +
    "xmlns:w='urn:schemas-microsoft-com:office:word'" +

    strBody = strBody + "<!--[if gte mso 9]>" +
    "<xml>" +
    "<w:WordDocument>" +
    "<w:View>Print</w:View>" +
    "<w:Zoom>100</w:Zoom>" +
    "</w:WordDocument>" +
    "</xml>" +
    strbulider.Append("<html><head>"+strBody+"</head><body> Content </body></html>");

    string strPath = Server.MapPath("~/docs/")+ docname";
    FileStream fStream = File.Create(strPath);
    StreamWriter sWriter = new StreamWriter(strPath);
    object filepath = strPath;
    Word.Application wordapp = new Word.Application();
    Word.Document worddoc = null;
    wordapp.Visible = false;
    object missing = Type.Missing;
    object readOnly = false;
    object isVisible = false;
    worddoc = wordapp.Documents.Open( ref filepath, ref missing,
    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);
    string content = worddoc.ActiveWindow.Selection.ToString();//selects the content of document created
    worddoc.ActiveWindow.Selection.Copy();//copy selected content
    Word.Document newdoc = new Microsoft.Office.Interop.Word.Document();//create new document object
    newdoc.ActiveWindow.Selection.Paste();//paste the copied content
    newdoc.ActiveWindow.View.Type = Word.WdViewType.wdPrintView;//set type of newdoc to printlayout
    newdoc.ActiveWindow.Selection.Font.Name = "Times New Roman";

    It worked fine till day before yesterday.. but from yesteday not works... I traced the code and it creates the first document in weblayout. and i am opening it and copy and pasting contents to new document with printlayout.

    The problem is:

    application stalls while it trying to opening the document.. manually i opened that doument, it shows a convert file prompt box . so only application stalls because of not responding to that prompt box...

    my requirement is to create a word document from c# using html as mentioned above with printlayout and want to convert to pdf...

    please help me to clear the issue...

     Thanks in advance..

    Thursday, August 8, 2013 12:41 AM