OPEN WORD DOCUMENT USING C# [Resolved]

Posted by Gudevg under C# on 4/16/2012 | Points: 10 | Views : 18957 | Status : [Member] | Replies : 6
Hi everyone,

I need to open a word document using c#, Any suggestions?

Deepakkumar G.


Responses

Posted by: Sakthi.Singaravel on: 4/16/2012 [Member] Silver | Points: 50

Up
0
Down

Resolved
hi deepakumar,

System.Diagnostics.Process.Start("winword.exe");

Regards,
Singaravel M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kk86kiran on: 4/16/2012 [Member] Starter | Points: 25

Up
0
Down
In c# we have stream writer class is available in System.IO namespace so by using this class we can read, write and we can do any thing with files or document try to search stream writer class examples in google

k.m.j.kiran

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/16/2012 [Member] Bronze | Points: 25

Up
0
Down
Use this COde:


protected void Page_Load(object sender, EventArgs e)


{



}



protected void Button1_Click(object sender, EventArgs e)

{




DetailsViewRow row = DetailsView1.Rows[3];




String strFileName = row.Cells[1].Text;



// Create an Application object

Microsoft.Office.Interop.Word.

ApplicationClass ac = new Microsoft.Office.Interop.Word.ApplicationClass();

Microsoft.Office.Interop.Word.

Application app = ac.Application;



// I'm setting all of the alerts to be off as I am trying to get



// this to print in the background

app.DisplayAlerts = Microsoft.Office.Interop.Word.

WdAlertLevel.wdAlertsNone;






object filename = Server.MapPath("Report") + "/" + strFileName;




string reportId = row.Cells[1].Text;

strFileName = Server.MapPath(

"Attachments") + "/" + reportId + ".doc";











object missingValue = Type.Missing;

app.Visible =

true;





// Using OpenOld so as to be compatible with other versions of Word

Microsoft.Office.Interop.Word.

Document document = app.Documents.OpenOld(ref filename,



ref missingValue, ref missingValue,



ref missingValue, ref missingValue, ref missingValue,



ref missingValue, ref missingValue, ref missingValue, ref missingValue);

app.Activate();









}


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/16/2012 [Member] Bronze | Points: 25

Up
0
Down
Or Refer This Link

http://social.msdn.microsoft.com/Forums/en-US/architecturegeneral/thread/0f5448a7-72ed-4f16-8b87-922b71892e07

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sarathy.Mca on: 4/18/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

Refer this code for you ques, this will be helpful for to open the any document in run time.

Step-1

Create applicetion:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
Height="64px" onselectedindexchanged="DropDownList1_SelectedIndexChanged"
Width="266px">
</asp:DropDownList>
</div>
</form>
</body>
</html>

Code using c#
********************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] objgetfiles = Directory.GetFiles(@"E:\Sarathy\Desktop");
if (objgetfiles.Length > 0)
{
for (int i = 0; i < objgetfiles.Length; i++)
{
DropDownList1.Items.Add(objgetfiles[i].ToString());
}
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(DropDownList1.SelectedItem.Text);

}
}


Parthasarathy.S

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sebas on: 3/12/2013 [Member] Starter | Points: 25

Up
0
Down
Hello,
If you need to read data from word document in your C# project, you may use some 3rd party .NET components.
For example you might want to look at this C# Word Reader:
http://eleriumsoft.com/Word_NET/WordReader/Examples/Read_Word_Document.aspx

Gudevg, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response