Click here to Skip to main content
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 1:37am
msweety149
Edited 8-Dec-12 2:48am
80.7K
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 269
1 Peter Leow 205
2 OriginalGriff 200
3 _Amy 190
4 Andreas Gieriet 180
0 OriginalGriff 7,540
1 Sergey Alexandrovich Kryukov 6,412
2 Maciej Los 3,849
3 Peter Leow 3,653
4 CHill60 2,702


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2014
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