473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

how to construct a template dynamically using c#

I need to construct a template such that it will contain both static and dynamic fields. For instance we can think of a employee registration form

----------------------------------
First Name: Friend1_Name
Last Name: Friend1_Surname

.
.
so on
-----------------------------------

As you see left part (first Name, Last Name, Phone No) is static, so
always the same, but the right portion of the stickers are filled by the
data that comes from the database.

Is there a way to implement it

=> Administrators will construct the template, put some graphics in a
Word Template and, somehow, specify the dynamic parts of the template. After
constructing the tamplate admin will upload the template to a web directory.
I will write an C#.NET code in order to connect to database
and create a Word document from the template that is uplaoded.

How may i fill the dynamic fields programmatically at the web server?
Just tell me away to solve this problem in c#, a I need an answer.here is my code

using System;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Configuration;
using System.Web.Security;
using System.Globalization;
using System.IO;
using Word;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Web.DynamicData;
using System.Web.SessionState;
using Microsoft.Office.Core;




protected void Button2_Click(object sender, EventArgs e)
{
string sql = ("Insert into regis ( first_name, last_name, date_of_birth, sex, addres, suburb, postcode, transport, telephone, mobile, other, health, english_fluency, heighest_level_edu, bank, account_type, branch_number, account_number, company_name, company_address, company_postcode, company_from, company_to, referee_name_title, referee_phone, position_duties, reason_for_leaving, company_name1, company_address1, company_from1, company_to1, referee_name_title1, referee_phone1, position_duties1, reason_for_leaving1 ) values ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox5.Text + "','" + DropDownList1.SelectedValue + "','" + TextBox4.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + TextBox9.Text + "','" + TextBox12.Text + "','" + TextBox13.Text + "','" + TextBox14.Text + "','" + DropDownList3.SelectedValue + "','" + DropDownList2.SelectedValue + "','" + TextBox10.Text + "','" + TextBox15.Text + "','" + TextBox16.Text + "','" + TextBox17.Text + "','" + TextBox18.Text + "','" + TextBox20.Text + "','" + TextBox21.Text + "','" + TextBox22.Text + "','" + TextBox30.Text + "','" + TextBox31.Text + "','" + TextBox24.Text + "','" + TextBox25.Text + "','" + TextBox23.Text + "','" + TextBox26.Text + "','" + TextBox32.Text + "','" + TextBox33.Text + "','" + TextBox35.Text + "','" + TextBox36.Text + "','" + TextBox37.Text + "','" + TextBox38.Text + "','" + TextBox39.Text + "','" + TextBox40.Text + "')");
string constr = "server=SQLPROD; uid=fb; password=Cato123; database=registration";

SqlConnection conn = new SqlConnection(constr);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
//Response.Redirect("Default1.aspx");
conn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox5.Text = "";
DropDownList1.SelectedValue = "false";
TextBox4.Text = "";
TextBox7.Text = "";
TextBox8.Text = "";
TextBox9.Text = "";
TextBox12.Text = "";
TextBox13.Text = "";
TextBox14.Text = "";
DropDownList3.SelectedValue = "false";
DropDownList2.SelectedValue = "false";
TextBox10.Text = "";
TextBox15.Text = "";
TextBox16.Text = "";
TextBox17.Text = "";
TextBox18.Text = "";
TextBox20.Text = "";
TextBox21.Text = "";
TextBox22.Text = "";
TextBox30.Text = "";
TextBox31.Text = "";
TextBox24.Text = "";
TextBox25.Text = "";
TextBox23.Text = "";
TextBox26.Text = "";
TextBox32.Text = "";
TextBox33.Text = "";
TextBox35.Text = "";
TextBox36.Text = "";
TextBox37.Text = "";
TextBox38.Text = "";
TextBox39.Text = "";



}
protected void Button3_Click(object sender, EventArgs e)
{

/*
Word.Application wrdApp;
Word_.Document wrdDoc;
Object oMissing = System.Reflection.Missing.Value;
Object oFalse = false;
Object oTrue = true;
Object oTemplate = "C:\\Users\\sdevi\\Documents\\Visual Studio 2010\\WebSites\australian staffing agency\\Application For Employment.dot";
Object oFileName = "C:\\Users\\sdevi\\Documents\\Visual Studio 2010\\WebSites\australian staffing agency\\Application For Employment.doc";

try
{
System.IO.File.Delete("Application For Employment.doc");
System.IO.File.Create("Application For Employment.doc");
}
catch(Exception ex)
{
}

wrdApp = new Word.Application( );
wrdApp.Visible = true;
wrdDoc = wrdApp.Documents.Add(ref oTemplate,ref oMissing,ref oMissing,ref oMissing);

foreach(Word.FormField frmField in wrdDoc.FormFields)
{

frmField.Result = "2";
}

wrdDoc.SaveAs(ref oFileName ,ref oMissing ,ref oTrue ,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oTru,ref oTrue,ref
oMissing);
wrdDoc.Close(ref oTrue,ref oFalse,ref oMissing);
wrdDoc = null;
wrdApp = null;
}
*/

}
}
Sep 13 '10 #1
0 1073

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jon | last post by:
I need to generate an XML File dynamically using ASP and a SQL Database. I don't have time to learn php or any other programing language. I need a ASP page to either append information to an XML...
4
by: dekern | last post by:
I have been trying to set the default text value of a TextArea element for about a day now without any luck. Similar to the code used to set the Text field below I would like to use the returned...
3
by: Jarek Mielcarek | last post by:
hi all, in xml file I have some fields which are source for <textarea> element. I'd like to transform this file using xslt and set the rows property of <textarea> depend of lines in some source...
0
by: Vrushal | last post by:
Hii HOW TO: Transfer Data to an word Template by Using ASP.NET What i m trying to do is .. User will select the word Template (dot file) from the asp.net page, and when i ll click SAVE i want...
1
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created...
6
by: Simon Verona | last post by:
I would normally use code such as : Dim Customer as new Customer Dim t as new threading.thread(AddressOf Customer.DisplayCustomer) Customer.CustomerId=MyCustomerId t.start Which would create...
5
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button....
2
by: santoshsri | last post by:
Hello, I will have to add textboxes in a datagrid Dynamically using Add button in C# Can anyone provide me a code snippet for this work. Thanks , San
7
by: tthunder | last post by:
Hi @all, I have a trivial question, but I cannot find any answer :( <xsl:template match="note"> <b>Note:</b> </xsl:template> <xsl:template match="note"> <p><!-- CALL <xsl:template...
3
by: itsSase | last post by:
Is there any way to change a Div ID - dynamically using Javascript...?????
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.