Converting data into Word Doc(Read Only)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dotNetDummi
    New Member
    • Nov 2007
    • 9

    Converting data into Word Doc(Read Only)

    Hi experts, I have a task to print some data into a word document .I need to set the word document to readOnly.

    It's working but user still can edit. Is there any thing I can do whereby user cannot edit the document?

    Code:
    //        Word.ApplicationClass oWordApp = new Word.ApplicationClass();
                //        object missing = System.Reflection.Missing.Value;
                //        object readOnly = true;
                //        object fileName = Server.MapPath("worddoc.doc");
                //        object isVisible = true;
                //        object password =System.Reflection.Missing.Value;
                //        Word.Document oWordDoc = oWordApp.Documents.Add(ref missing, ref missing,
                //        ref missing, ref isVisible);
                //        oWordDoc.Activate();
                //        oWordApp.Selection.TypeText(form);
                        
                //        oWordApp.Selection.TypeParagraph();
                //        oWordDoc.SaveAs(ref fileName,ref missing, ref missing, ref password, ref
                //missing, ref missing,
                //        ref readOnly, ref missing, ref missing, ref missing, ref missing, ref
                //missing, ref missing,
                //        ref missing, ref missing, ref missing);
                //        oWordApp.Application.Quit(ref missing, ref missing, ref missing);

    This is another method that I've done but the word document is not read only.

    Code:
    Response.Clear();
            Response.AddHeader("content-disposition", "attachment;filename=form1.doc");
            Response.Charset = "";
    
            Response.ContentType = "application/vnd.word";
            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            htmlWrite.Write("<center>"+form+"</center>");
            htmlWrite.WriteBreak(); htmlWrite.WriteBreak();
            
            GridView1.RenderControl(htmlWrite);
            htmlWrite.WriteBreak();
            gv_retrieve_status.RenderControl(htmlWrite);
    
            System.IO.Directory.CreateDirectory(Server.MapPath("Docs/") + projectID + "/EP/");
            //(Server.MapPath("Docs/" + projectID + "/Form1/") + projectID + "_form1.doc");
            Response.Write(stringWrite.ToString());
            Response.End();
    Please help. Thanks
Working...