How can I create a document from my program with some coded portions?
-
Hi, I have some .html templates, when the Form is submitted the code creates the document and modifies certain portions of the document with information obtained from the fields in the code. What is a better way to do this, will XML help at all? I'm presently using StringBuilder to develop the content. Ideally I could reopen the documents and quicky make changes rather than re-create them each time.
-
Hi, I have some .html templates, when the Form is submitted the code creates the document and modifies certain portions of the document with information obtained from the fields in the code. What is a better way to do this, will XML help at all? I'm presently using StringBuilder to develop the content. Ideally I could reopen the documents and quicky make changes rather than re-create them each time.
One way would be to have a template file with the sections that you want to replace marked out with unique text, then do a find/replace on this.
private string Replace(string item, string replace, string text) { if (item == null || item.Trim() == string.Empty) return string.Empty; return Regex.Replace(item, replace, text, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase); }
This is a method to do a replace based on a regular expression. Call this as:
text = Replace(text, "^^ Unique Text ^^", "My replacement text");
Deja View - the feeling that you've seen this post before.