Last post Feb 03, 2016 10:44 AM by ramiwahdan
Feb 03, 2016 08:47 AM|ramiwahdan|LINK
I am trying to add "fullname" field from the asp.net to the word template file. the template is like this
file name: Name.dotx
My Name is [FULLNAME]
now here is my code but i won't work! it will generate an empty page!
protected void Button2_Click(object sender, EventArgs e)
//Create a new filename
string strFileName = System.Guid.NewGuid().ToString();
string strPathRoot = "d:\\";
string strPath = strPathRoot + "Name.dotx";
string str = System.IO.File.ReadAllText(strPath);
StringBuilder sb = new StringBuilder();
//replace the text
//save it out
TextWriter tw = new StreamWriter(strPathRoot + "1.docx");
// write a line of text to the file
// close it
I am not sure why i am not getting anything or even any error.
Feb 03, 2016 08:59 AM|bhargav5126|LINK
If you have text in Template file is like this "My name is [FullName]"
Then you should change this line sb.Replace("<<FULLNAME>>", "RAMI");
by sb.Replace("[FullName"]", "RAMI");
Let me know if you resolve this issue.
Feb 03, 2016 09:10 AM|ramiwahdan|LINK
I tried now it creates the file but it won't open:
there is a problem with the contents
file is corrupted!
Feb 03, 2016 10:30 AM|bhargav5126|LINK
please attach demo template file with code file.
Feb 03, 2016 10:44 AM|ramiwahdan|LINK
I found the solution and it is very clear.