Question : Insert words into word

Hi,

I've been trying to get this to work:

http://www.codeproject.com/KB/aspnet/Word_Template_Programming.aspx

(Code attached)

The code seems to run okay, but the resulting file is always jibberish -

rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff31507\deff0\stshfdbch31506\stshfloch31506\stshfhich31506\stshfbi31507\deflang2057\deflangfe2057\themelang2057\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f34\fbidi \froman\fcharset1\fprq2{\*\panose 02040503050406030204}Cambria Math;}
{\f37\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;}{\flomajor\f31500\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}
{\fdbmajor\f31501\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fhimajor\f31502\fbidi \froman\fcharset0\fprq2{\*\panose 02040503050406030204}Cambria;}
{\fbimajor\f31503\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\flominor\f31504\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304

I'm sure its something simple but I can't figure it out?

Any ideas?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
Public Sub GetOutput()
' Declare a scripting object.
        Dim td As Object = Server.CreateObject("Scripting.FileSystemObject")

        'Copy File
        td.CopyFile(Server.MapPath("./") & "test.rtf", Server.MapPath("./") & "temp.rtf")

        ' set the file path in a string variable.
        Dim strFilePath As String = Server.MapPath("./") & "temp.rtf"

        'Now open the termporary file in Read mode.
        Dim fs2 As New IO.FileStream(strFilePath, IO.FileMode.Open, IO.FileAccess.Read)

        'Declare d as a stream Reader
        Dim d As New IO.StreamReader(fs2)

        Dim swrtarget As String

        'Initialise the stream reader d to the begining of the file.
        d.BaseStream.Seek(0, IO.SeekOrigin.Begin)

        swrtarget = d.ReadToEnd 'Read the file from Start to End in one go.
        d.Close() ' Close the Stream Reader

        Dim str As String
        Dim strValue As String
        Dim str1 As String
        Dim strValue1 As String


        'Now get the values from database.
        'Use can use a select query and a data reader to get the values.
        'Now set the file path to the Temporary file
        'Set the path to open Temporary
        strFilePath = Server.MapPath("./") & "temp.rtf"

        'Open the temporary file in Read-Write Mode.
        Dim fs1 As New IO.FileStream(strFilePath, IO.FileMode.Open, IO.FileAccess.ReadWrite)
        Dim s As New IO.StreamWriter(fs1) 'Declare a Stream Writer.

        'Replace the values with the values in the string read from Temporary.
        Dim ObjConn As New SqlConnection(strConn)
        Dim strSQL As String = "select common_key ,author from tbl_meta where ID = 1"
        Dim objComm As New SqlCommand(strSQL, ObjConn)
        ObjConn.Open()
        Dim myReader As SqlDataReader = objComm.ExecuteReader(CommandBehavior.CloseConnection)

        While myReader.Read

            strValue1 = myReader.GetValue(0).ToString()

            str1 = Replace(swrtarget.ToString, "##Address##", Trim(strValue1))

            strValue1 = myReader.GetValue(1).ToString()

            str1 = Replace(swrtarget.ToString, "##Name##", Trim(strValue1))

            'Similarly it will come for ##DOF## and ##desig###.


        End While

        'Close the Reader.
        myReader.Close()
        myReader = Nothing
        'Close the Connection.
        ObjConn.Close()
        ObjConn.Dispose()
        ObjConn = Nothing
        ' After replacing all the values write these values in the file2.rtf via the file write (s).

        s.WriteLine(str)

        'After writing the data in the stream writer the values must be flushed.

        s.Flush()

        'Close the stream writer.

        s.Close()

        fs1.Close()

        fs2.Close()


        'Now copy the details into the final file.

        'This file can be a .dc file.

        Dim td1 = Server.CreateObject("Scripting.FileSystemObject")

        td1.CopyFile(Server.MapPath("./") & "temp.rtf", Server.MapPath("./") & "final.doc")

        'Open a new window in the browser and display final.doc file to the user.

        Dim strtargetFilepath As String = " final.doc"

        Response.Write("<script> window.open('" & strtargetFilepath & "') </script>")


    End Sub

Answer : Insert words into word

>>2.  It is highlighting every instance of the 'term' letters within the name, versus just those at the beginning of the first and last names which is what I desire.
OK, then use:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
success: function(data) {
						var re=new RegExp('^('+request.term+')(.*)','i');
						
						response($.map(data.users, function(item) {
							
							return {
								label: item.first_name.replace( re, "<strong class='hit'>$1</strong>$2") + " " + item.last_name.replace( re, "<strong class='hit'>$1</strong>$2"),
								value: item.first_name + " " + item.last_name,
								company: item.co_name
							}
						}))
					}
Random Solutions  
 
programming4us programming4us