473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Creating rtf document using ASP.NET

Hi,

I am trying to create rtf document using C# and ASP.NET.

I have seen a sample code in asp:
http://support.microsoft.com/kb/270906/

I tried to do the same using C#, but rtf controls are not recognized.
Document is not formatted and formatting information is just displayed
in plain text.

My code:
FileStream sw =
File.Open(Server.MapPath("Sample1.doc"),FileMode.T runcate);
StreamWriter MyFile = new StreamWriter(sw);
MyFile.WriteLine("{\rtf1 ");
string sRTF = string.Empty;
sRTF = @"{\par This is some {\b bold} text.\par}";
MyFile.WriteLine(sRTF);
MyFile.WriteLine("}");
MyFile.Close();
sw.Close();
Response.Write("<META HTTP-EQUIV='REFRESH'
Content=0;URL=Sample1.doc>");

The output in Sample1.doc should be

This is some bold text.

Instead it is,

{tf1
{\par This is some {\b bold} text.\par}
}

What's wrong? Please help me.

Rachana

Sep 11 '06 #1
2 7646
Is it because you aren't escaping the reserved characters such as "\"?

"rachana" <ra************@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Hi,

I am trying to create rtf document using C# and ASP.NET.

I have seen a sample code in asp:
http://support.microsoft.com/kb/270906/

I tried to do the same using C#, but rtf controls are not recognized.
Document is not formatted and formatting information is just displayed
in plain text.

My code:
FileStream sw =
File.Open(Server.MapPath("Sample1.doc"),FileMode.T runcate);
StreamWriter MyFile = new StreamWriter(sw);
MyFile.WriteLine("{\rtf1 ");
string sRTF = string.Empty;
sRTF = @"{\par This is some {\b bold} text.\par}";
MyFile.WriteLine(sRTF);
MyFile.WriteLine("}");
MyFile.Close();
sw.Close();
Response.Write("<META HTTP-EQUIV='REFRESH'
Content=0;URL=Sample1.doc>");

The output in Sample1.doc should be

This is some bold text.

Instead it is,

{tf1
{\par This is some {\b bold} text.\par}
}

What's wrong? Please help me.

Rachana

Sep 11 '06 #2
Thanks a ton for pointing out this. I had forgotten to escape "\" in
the first line
MyFile.WriteLine("{\rtf1 ");

Changed it to MyFile.WriteLine("{\\rtf1 ") and it is working well.

Again thanks.
Rachana

Sep 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: TP | last post by:
Hi, I have reached a situation where I have to create small pieces of xml (around 8k characters) within my java app. Right now I am using stringbuffer to create the xml which does not go against...
24
by: jonathon | last post by:
Hi all, I have a web app with a popup window for entering data. I don't want to access the web every time this window is opened, as most of the app is AJAX. But I can't figure out how to open...
16
by: Mcginkel | last post by:
I am trying to find a way to load XHTML content in an Iframe. I use to do this in html by using the following code : var iframeObject = document.createElement("iframe");...
6
by: Adam Tilghman | last post by:
Hi all, I have found that IE doesn't seem to respect the <SELECT> "multiple" attribute when set using DOM methods, although the attribute/property seems to exist and is updated properly. Those...
0
by: Phani | last post by:
Hi All, I have 3 questions here: 1) Problem creating a SPFolder object: I am trying to create a SPFolder object for a document/picture library using the following code with SOM
4
by: GRenard | last post by:
Hi, I'm trying just to display a table on a webpage using DOM elements created dynamically. I really don't understand why IE doesn't display the document successfully... If I make a...
9
by: William | last post by:
Heya, I have been looking all over Google for ways to *create* an XML document using any Javascript object, and it seems that no one has ever tried or ever needed this. I want to send the...
3
by: patrickkellogg | last post by:
I have this code when you click the buttom is suppose to add a job history. it works with firefox, opera, but not ie. (please note - new entries don't have all the elements in them yet, but...
2
by: Moses | last post by:
Hi All, Is is possible to catch the error of an undefined element while creating an object for it. Consider we are not having an element with id indicator but we are trying to make the object...
1
by: shmodi | last post by:
Hi All, I am new here and want to get some help for speeding up and resolving IE issue while creating tree using ajax. My tree contains radio buttons at each level and I am getting all tree...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.