hello!
i need to know how u can add a doc or rtf file to Resources. I need to then open the file and show with same formatting in a rich text box.
i need to do it urgently..please help me.
i am using VS 2010,c sharp.

ThankYou all

Dani AI

Generated

: was right that embedding an RTF is the simplest route. Two important facts up front: a WinForms RichTextBox understands RTF (and plain text) but not Word .doc/.docx formatting directly; and most failures come from the resource not actually being embedded or from using the wrong resource name.

A reliable approach (works in VS2010/.NET): add the .rtf file to the project, set its Build Action to Embedded Resource, then load it from the assembly and call LoadFile with RichTextBoxStreamType.RichText. Listing resource names helps find the correct fully qualified name.

using System.Reflection;
using System.IO;

// debug: list embedded names
var asm = Assembly.GetExecutingAssembly();
foreach (var n in asm.GetManifestResourceNames())
    Console.WriteLine(n);

// load and display
using (Stream s = asm.GetManifestResourceStream("MyAppNamespace.FolderName.MyFile.rtf"))
{
    richTextBox1.LoadFile(s, System.Windows.Forms.RichTextBoxStreamType.RichText);
}

If the .rtf was added via Project -> Properties -> Resources and shows up as a string in Properties.Resources, it can also be used directly: set richTextBox1.Rtf = Properties.Resources.MyRtfResource or wrap a byte[] resource in a MemoryStream and call LoadFile.

For .doc files: convert to RTF before loading. Options include pre-saving RTF versions, using Word interop to convert (not recommended on servers — see Microsoft guidance), or using a library such as Aspose.Words/Spire.Doc to convert programmatically.

References:

Common troubleshooting points: verify the resource name from GetManifestResourceNames(), confirm Build Action = Embedded Resource, reset stream position to 0 before loading, and use RichTextBoxStreamType.RichText.

Recommended Answers

All 2 Replies

i tried that link.but id didnt work..someone pleassssssseee helppp..
thanks a lot jfarrugia.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.