Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create rtf file and display on client. 1

Status
Not open for further replies.

petermeachem

Programmer
Aug 26, 2000
2,270
GB
What I am trying to do is to read an rtf file, replace some text with text from a database (name and address etc), save it to a folder and display it in word on the user's pc.
To display the file I am shelling to it using a couple of lines of javascript. The code that reads, modifies and writes the file saves the path to the file in a textbox. This I hoped the javascript could use.
Doesn't work. I think that the javascript sub is running before the database related code so there is no path to shell to.
Does that seem likely? If so, how can I do this? I've been struggling away for ages at it. All the individual bits work, just the link from the created filename and the javascript on the browser is not working.
 
javascript runs on the client, the file and db are accessed via the server, so you either need to move the js to c#/vb server code, or use web services to stream the content to the client via js.

the best method is to load the file using a generic handler (ashx), change content type and stream the file.
the most common example is load a image from a database to the webpage.

connect to db
get image as byte[]
change request content type to jpeg
stream bytes to client

in your case you will
open filestream from rtf
change request type to rtf (or whatever it should be)
send filestream to response

Important make sure you close & dispose of the stream after sending it to the response. if not you'll eat up resources and lock files quickly.

to access the rtf from a response.redirect or hyperlink you use [tt]~/rtfhandler.ashx?id=###[/tt] where ### is some identifier of the report.

there are also some posts on this forum about loading pdfs from a database. if you can find them the same concepts apply.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
OK, I have found your code to do that.
If I change from pdf to rtf how does the file end up in ms word? I don't understand.
 
ms word is different than rtf. rtf is application egnostic. Word docs are specific to an application. when you change the content type the browser knows to render the file with a different program.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I'm not clear on this. The users need to end up with a document in ms word that they can edit and where I have filled in the name and address etc.
Will your method achieve this?
 
yes. it's the same process when you click on a pdf and it opens in a browser window. instead of adobe reader, ms word will open, they can modify the document and save a local copy on their computer.

depending on where you use inline or attachment style headers will determine if the user gets prompted to save/open/cancel or if the document just opens in the browser.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top