Click here to Skip to main content
16,019,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

.apsx.cs file:
C#
protected void CreateWord()
        {
            AdminActivityBL objAdminActivity = new AdminActivityBL();
            objAdminActivity.SaveCreateWord();

            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);

            objWordDoc.Activate();
            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 = 
                { 
                    name, 
                    false, 
                    Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString, 
                    value 
                };

                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:
C#
public DataSet GetAddTemplateDetails(Template objtemplate)
        {
            AdminActivityDB objAdminActivityDB = new AdminActivityDB();
            return objAdminActivityDB.GetAddTemplateDetails(objtemplate);
        }

Data access layer:
C#
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
Updated 8-Dec-12 2:48am
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900