Well, you didn?t specify what language you wanted an answer in but here is on in Asp.Net (VB.Net) that accomplishes it without anything too fancy and can be adapted to any language.
1. Create the document that you want to inject the users name into.
2. Save it as Xml from Word. (documentTemplate.xml)
3. Edit the Xml file and put some kind of a token where you want to place the user name. In this case we are using 6 X?s, so XXXXXX. See the Xml snippet below.
4. Put the Xml version of the document on your website.
5. Each time you need to serve it to a user, you programatically:
a. Open the xml and read it into a temp variable.
b. Replace the token (XXXXXX) with the user name.
c. Write the temp variable back out to the file system.
d. Redirect the user to the file.
------This is part of the saved Word Xml. You can see where the token is added.
Hello my name is XXXXXX.
--------Code to do this in vb.net and Asp.Net. It?s taken for granted in this example that all files are located in the web root directory and all permissions, etc have been granted. An important update to this code would be to make the output file name unique for each user so that you don?t have a race condition.
Dim reader As StreamReader
Dim writer As StreamWriter
Try
Dim sourcePath As String = Path.Combine(Server.MapPath("."), " documentTemplate.xml")
reader = New StreamReader(sourcePath)
Dim body As String = reader.ReadToEnd.Replace("XXXXXX", "New User Name")
Dim destinationPath As String = Path.Combine(Server.MapPath("."), "NewFileForUser.doc")
writer = New StreamWriter(destinationPath)
writer.Write(body)
Response.Redirect("NewFileForUser.doc")
Catch ex As Exception
debug.writeline(ex.Message)
Throw
Finally
If Not reader Is Nothing Then reader.Close()
If Not writer Is Nothing Then writer.Close()
End Try