0

I have a situation where I have to generate a MS Word report by exporting the Repeater to Word Document. I am doing it but my requirement is to Save the MS Word file either on Server / Database. How can I save that file on Server/Database after generating the Word Document?

Requirement is to Generate and Save the Word file on either Server / Database and also the generated or saved file should be a Read-Only file. How can I do it ?

Here is the Code I am using to generate Word file..

protected void DisplayRepeater()
    {
        if (ddlDivRAHQ.SelectedValue == "DIV")
        {
            Repeater_PrintFinalReport.DataSource = new ReportItems().Get_Rpt_Items_Div_Chief(Convert.ToInt32(Session["UserNumber"]), DateTime.Parse(Session["ReportStartDate"].ToString()), DateTime.Parse(Session["ReportEndDate"].ToString()), ddlDivRAHQ.SelectedValue.ToString()).OrderBy(x => x.OrgNum).ThenBy(x => x.Office_Location).ThenBy(x => x.Site_Desc).ToList();
        }
        else
        {
            Repeater_PrintFinalReport.DataSource = new ReportItems().Get_Rpt_Items_Div_Chief(Convert.ToInt32(Session["UserNumber"]), DateTime.Parse(Session["ReportStartDate"].ToString()), DateTime.Parse(Session["ReportEndDate"].ToString()), ddlDivRAHQ.SelectedValue.ToString()).Where(x=>x.Finalized == 1).OrderBy(x => x.Site_Desc).ToList();
        }

        Repeater_PrintFinalReport.DataBind();
        Repeater_PrintFinalReport.Visible = true;
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=" + ddlDivRAHQ.SelectedValue + "_WeeklyReport_" + DateTime.Now.ToShortDateString() + ".doc");
        Response.Charset = "";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/vnd.word";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
        Repeater_PrintFinalReport.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());
        Response.End();
    }
Kara
  • 6,115
  • 16
  • 50
  • 57
msbyuva
  • 3,467
  • 13
  • 63
  • 87

1 Answers1

-1

I have taken the help from the below link

http://support.microsoft.com/kb/316384

MS.Word using Microsoft.Office.Interop.Word

How to automate Microsoft Word to create a new document by using Visual C#

msbyuva
  • 3,467
  • 13
  • 63
  • 87
  • -1: you cannot use Office Interop from a server application like ASP.NET. It just doesn't work reliably because those APIs were meant to be used from a desktop application. – John Saunders Aug 01 '11 at 16:17