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