Iam trying to open/Edit a word document for changes as below on a web page(default.aspx)
Its works in visual studios but not on the web page.
Can anyone help me get this resolved.
Below is the code iam using to open the word document:
Its works in visual studios but not on the web page.
You need to remember that ASP.NET runs on server side. In your development environment, when you're using Visual Studio, your PC is used as the server. But in a production environment, what you're doing here is opening a Word document on the web server!
Also, Microsoft.Office.Interop should not be used in a web environment!
"Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit
unstable behavior and/or deadlock when Office is run in this environment."
Can you or anyone please provide me an alternative to accomplish this,with some code examples.
That depands on what you want to accomplish? Do you want to edit the word document in ASP.NET on serverside, or do you want the user to edit the document?
This works in Vstudio,Opens word document,I can make changes,and than save.
When i use the same default page as http://merge.com/default.aspx, Word document is never opened.The page does nothing.
I already explained this in my first reply! The document is opened on the server (provided Word is installed on the server!), on your development machine the server is your local PC so it will work, but in a web environment this will NOT work. I think you should
do some more research on what Web develpment is all about! When a user will edit a word document on his local machine, is not connected whatsover with your website!
Iam lot more confused on this.What all i need to do is
1.Browse a file using fileupload
2.Use the file upload file and when hit on a button,the file needs to opened/edited(user will have word on his local machine/where we he uses this application).
3.User makes necessary changes,saves the file.
How to do this?
For this,i downloaded the file uploaded file to the server,saved in a temp location,so user needs to open that temp file,edited,and saved.
Can you please help or point me in the right direction if iam doing wrong.
Thanks so much for your help.
Vega Vilas
Please Mark As Answer if this reply helps you.
I understand what you want, but you don't seem to understand that what you want is not possible in a web environment!
1. That's no problem
2. This is were the problem start. A document that is saved on the webserver, canot be edited by a user that's visiting a website. When they want to edit the document, it first need to be downloaded to their local computer, where it can be edited, but this
is a copy of he document that is stored on the webserver.
3. So when it is edited localy, it should be copied back to the web server
VegaVilas
Member
34 Points
57 Posts
Open/Edit a word document on a web page
Apr 20, 2010 04:36 PM|LINK
HI,
Iam trying to open/Edit a word document for changes as below on a web page(default.aspx)
Its works in visual studios but not on the web page.
Can anyone help me get this resolved.
Below is the code iam using to open the word document:
protected void Button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
object file = "C:\\temp1\\poForM.doc";
object objFalse = false;
object objTrue = true;
object missing = System.Reflection.Missing.Value;
object emptyData = string.Empty;
wordApp.Visible = true;
Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref file, ref objFalse, ref objFalse,
ref objFalse, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref objTrue,
ref missing, ref missing, ref missing);
aDoc.Activate();
}
The document is never shown/opened.
Thanks in advance.
Please Mark As Answer if this reply helps you.
hans_v
All-Star
35986 Points
6550 Posts
Re: Open/Edit a word document on a web page
Apr 20, 2010 08:16 PM|LINK
You need to remember that ASP.NET runs on server side. In your development environment, when you're using Visual Studio, your PC is used as the server. But in a production environment, what you're doing here is opening a Word document on the web server!
Also, Microsoft.Office.Interop should not be used in a web environment!
"Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment."
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2
Especially when you're calling wordApp.Visible = true, I think you're server will crash very soon
VegaVilas
Member
34 Points
57 Posts
Re: Open/Edit a word document on a web page
Apr 21, 2010 01:38 PM|LINK
Thanks a lot hans for your reply.
Can you or anyone please provide me an alternative to accomplish this,with some code examples.
Thanks in advance,
Terry.
Please Mark As Answer if this reply helps you.
hans_v
All-Star
35986 Points
6550 Posts
Re: Open/Edit a word document on a web page
Apr 21, 2010 01:58 PM|LINK
That depands on what you want to accomplish? Do you want to edit the word document in ASP.NET on serverside, or do you want the user to edit the document?
VegaVilas
Member
34 Points
57 Posts
Re: Open/Edit a word document on a web page
Apr 21, 2010 02:02 PM|LINK
I want the user to edit,make necessary changes ,save the file and use it for text selection (this on a different button).
Thank you,
Please Mark As Answer if this reply helps you.
hans_v
All-Star
35986 Points
6550 Posts
Re: Open/Edit a word document on a web page
Apr 21, 2010 03:37 PM|LINK
That's easy!
http://forums.asp.net/t/1547457.aspx#3791722
But then you must realize that the user is opening the document on his local computer (Wod needs to be installed)
This is the problem. When the user edits the document, it's up to him to upload the file to the server
VegaVilas
Member
34 Points
57 Posts
Re: Open/Edit a word document on a web page
Apr 21, 2010 03:59 PM|LINK
Thanks for your reply hans.
I already used that code ,here is my full code,the below one needs to be worked on web page.
protected string uploadFile = string.Empty;
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
uploadFile = Path.Combine(Request.ApplicationPath, @"temp1\" + Path.GetFileName(fleAttach.PostedFile.FileName));
fleAttach.SaveAs(uploadFile);
txtHidden.Text = uploadFile;
OpenWord(uploadFile);
}
public void OpenWord(string wordFileName)
{
object fileName = wordFileName;
object objFalse = false;
object objTrue = true;
object missing = System.Reflection.Missing.Value;
object emptyData = string.Empty;
WordApp.Visible = true;
Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref objFalse, ref objFalse,
ref objFalse, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref objTrue,
ref missing, ref missing, ref missing);
aDoc.Activate();
}
This works in Vstudio,Opens word document,I can make changes,and than save.
When i use the same default page as http://merge.com/default.aspx, Word document is never opened.The page does nothing.
Can you or anyone please help me figure out this,i am strugging on this since a month.
Thanks in advance.
Please Mark As Answer if this reply helps you.
hans_v
All-Star
35986 Points
6550 Posts
Re: Open/Edit a word document on a web page
Apr 21, 2010 04:02 PM|LINK
VegaVilas
Member
34 Points
57 Posts
Re: Open/Edit a word document on a web page
Apr 21, 2010 04:23 PM|LINK
Thanks for your reply hans.
Iam lot more confused on this.What all i need to do is
1.Browse a file using fileupload
2.Use the file upload file and when hit on a button,the file needs to opened/edited(user will have word on his local machine/where we he uses this application).
3.User makes necessary changes,saves the file.
How to do this?
For this,i downloaded the file uploaded file to the server,saved in a temp location,so user needs to open that temp file,edited,and saved.
Can you please help or point me in the right direction if iam doing wrong.
Thanks so much for your help.
Please Mark As Answer if this reply helps you.
hans_v
All-Star
35986 Points
6550 Posts
Re: Open/Edit a word document on a web page
Apr 21, 2010 04:38 PM|LINK
I understand what you want, but you don't seem to understand that what you want is not possible in a web environment!
1. That's no problem
2. This is were the problem start. A document that is saved on the webserver, canot be edited by a user that's visiting a website. When they want to edit the document, it first need to be downloaded to their local computer, where it can be edited, but this is a copy of he document that is stored on the webserver.
3. So when it is edited localy, it should be copied back to the web server