Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can I create a document from my program with some coded portions?

How can I create a document from my program with some coded portions?

Scheduled Pinned Locked Moved C#
questionhtmlwpfxmlhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cfer83
    wrote on last edited by
    #1

    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.

    P 1 Reply Last reply
    0
    • C Cfer83

      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.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups