开发者

Export Repeater to MS Word and SAVE the Word file on Server or Database C#, ASP.NET

开发者 https://www.devze.com 2023-03-21 22:09 出处:网络
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 ca

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.StringW开发者_运维百科riter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
        Repeater_PrintFinalReport.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());
        Response.End();
    }


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#

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号