Creating rtf document using ASP.NET

R

rachana

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.Truncate);
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
 
K

Ken Cox [Microsoft MVP]

Is it because you aren't escaping the reserved characters such as "\"?
 
R

rachana

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top