Click here to Skip to main content
11,436,156 members (60,826 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hi,

.apsx.cs file:
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:
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 2:37am
msweety149
Edited 8-Dec-12 3:48am
(no name)90.4K
v2

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



Advertise | Privacy | Mobile
Web04 | 2.8.150428.2 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2015
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