i want to add a word document into c sharp code as reference..and while clicking a button in the form,the word file has to get opened..

Recommended Answers

All 5 Replies

Use Process.Start() to open a file.

static void Main()
    {
	// A.
	// Open specified Word file.
	OpenMicrosoftWord(@"C:\Users\Sam\Documents\Gears.docx");
    }

    /// <summary>
    /// Open specified word document.
    /// </summary>
    static void OpenMicrosoftWord(string f)
    {
	ProcessStartInfo startInfo = new ProcessStartInfo();
	startInfo.FileName = "WINWORD.EXE";
	startInfo.Arguments = f;
	Process.Start(startInfo);
    }

you can even run an exe file by using Process.Start()

Process.Start("sample.exe");

but i have to run this code in different computers.so giving the path by default is not possible right..can i add the word document to my code and display it later by pressing a button in the form.

Rather adding the document to you code, add the file to your project and deploy it in other computers!!

Actually i am supposed to send only exe file and dll..is there no other way?

It sounds to me like you would need to create the MS-WORD document in code, stream it out to a temporary location determined by your application, then open it.

The Web abounds with examples of creating Office Documents in .NET.

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.