Click here to Skip to main content
12,895,064 members (61,761 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET

.apsx.cs file:
protected void CreateWord()
            AdminActivityBL objAdminActivity = new AdminActivityBL();
            object fileName = "D:\\MyWord.dotx";
            object novalue = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Word.Application objWord = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document objWordDoc = objWord.Documents.Add(ref novalue, ref novalue, ref novalue, ref novalue);
            DataSet ds = new DataSet();
            ds = objAdminActivity.GetAddTemplateDetails(objTemplate);
            DataTable table = ds.Tables[0];
            DataRow row = table.Rows[0];
            foreach (DataRow dr in table.Rows)
                object oDocCustomProps = objWordDoc.CustomDocumentProperties;
                Type typeDocCustomProps = oDocCustomProps.GetType();
                string name = string.Format("{0}", dr["AttrName"]);
                string value = string.Format("{0}", dr["AttrValue"]);
                string type = string.Format("{0}", dr["AttrType"]);

                object[] oArg = 
                typeDocCustomProps.InvokeMember("Add", BindingFlags.Default | BindingFlags.InvokeMethod, null, oDocCustomProps, oArg);
                objWord.Visible = true;

            objWordDoc.SaveAs(ref fileName, ref novalue, ref novalue, ref novalue,
                        ref novalue, ref novalue, ref novalue, ref novalue, ref novalue,
                        ref novalue, ref novalue);
            //objWord.Quit(ref novalue, ref novalue, ref novalue);

Business layer:
public DataSet GetAddTemplateDetails(Template objtemplate)
            AdminActivityDB objAdminActivityDB = new AdminActivityDB();
            return objAdminActivityDB.GetAddTemplateDetails(objtemplate);

Data access layer:
public DataSet GetAddTemplateDetails(Template objTemplate)
            Database objDB = new SqlDatabase(ConfigurationHelper.ConnectionString);
            using (DbCommand objCMD = objDB.GetStoredProcCommand(GET_ADDTEMPLATE_DETAILS))
                objDB.AddInParameter(objCMD, "@TemplateId", DbType.Int32, objTemplate.TemplateId);
                DataSet retDS = objDB.ExecuteDataSet(objCMD);
                return retDS;
Posted 8-Dec-12 1:37am
Updated 8-Dec-12 2:48am

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170424.1 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100