6 Replies - 5236 Views - Last Post: 28 August 2009 - 05:22 AM Rate Topic: -----

#1 vyasdev2005  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-April 09

Error opening word document in asp.net

Posted 21 April 2009 - 06:19 AM

I am trying to opening Word file in asp.net application. I Try Following Code For That,
Private oWordAppl As Word.Application
	Private oDoc As Word.Document
	Public Sub New()
		oWordAppl = New Word.Application
	End Sub
	Public Sub Open(ByVal strfileName As String)
		Dim fieName As Object = strfileName
		Dim readOnly1 As Object = False
		Dim isVisible As Object = True
		Dim missing As Object = System.Reflection.Missing.Value

		oDoc = oWordAppl.Documents.Open(fieName, missing, readOnly1, missing, missing, missing, missing, missing, missing, missing, missing, isVisible)
		oDoc.Activate()
	End Sub


And this code for Opening file,

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
		Dim Test As New WordAppl
		Dim TamplatePath As String = ConfigurationManager.AppSettings("WordMod")
		Dim DocumentPath As String = ConfigurationManager.AppSettings("WordDoc")
		Test.Open(TamplatePath & "Test.Doc")
		Test.SaveAs(DocumentPath & "Test.Doc")
		Test.Open()
	End Sub


All this works fine in View In Browser, But when I publish that Page The file not opening and on Click of Button, Browser running continuosly, but cant find file.

Please Help ME out,
Thanks.....

Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

This post has been edited by PsychoCoder: 21 April 2009 - 06:34 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Error opening word document in asp.net

#2 Ian2009  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 31
  • Joined: 07-April 09

Re: Error opening word document in asp.net

Posted 21 April 2009 - 11:55 AM

have you tried to use Server.MapPath()
Test.Open(Server.MapPath(TamplatePath & "Test.Doc"))

Was This Post Helpful? 0
  • +
  • -

#3 vyasdev2005  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-April 09

Re: Error opening word document in asp.net

Posted 22 April 2009 - 01:51 AM

No luck, Thats not working, may be i should have to change path, but dont know what....
Was This Post Helpful? 0
  • +
  • -

#4 iwan_tjioe82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 20-April 09

Re: Error opening word document in asp.net

Posted 22 April 2009 - 02:06 AM

teoritically:
try checking the file is exist or not before running the code to open the file avoid using microsoft office component in your web application cause it's usually make your program crash
Was This Post Helpful? 0
  • +
  • -

#5 ezzatvar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-August 09

Re: Error opening word document in asp.net

Posted 27 August 2009 - 08:49 PM

View Postvyasdev2005, on 21 Apr, 2009 - 05:19 AM, said:

I am trying to opening Word file in asp.net application. I Try Following Code For That,
Private oWordAppl As Word.Application
	Private oDoc As Word.Document
	Public Sub New()
		oWordAppl = New Word.Application
	End Sub
	Public Sub Open(ByVal strfileName As String)
		Dim fieName As Object = strfileName
		Dim readOnly1 As Object = False
		Dim isVisible As Object = True
		Dim missing As Object = System.Reflection.Missing.Value

		oDoc = oWordAppl.Documents.Open(fieName, missing, readOnly1, missing, missing, missing, missing, missing, missing, missing, missing, isVisible)
		oDoc.Activate()
	End Sub


And this code for Opening file,

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
		Dim Test As New WordAppl
		Dim TamplatePath As String = ConfigurationManager.AppSettings("WordMod")
		Dim DocumentPath As String = ConfigurationManager.AppSettings("WordDoc")
		Test.Open(TamplatePath & "Test.Doc")
		Test.SaveAs(DocumentPath & "Test.Doc")
		Test.Open()
	End Sub


All this works fine in View In Browser, But when I publish that Page The file not opening and on Click of Button, Browser running continuosly, but cant find file.

Please Help ME out,
Thanks.....

Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)



Hi,
I am experiencing similar problem with opening word document programitically in ASP.Net environment.
I am just wondering if you finally found any solution for your problem.
Thanks
Ezzatvar
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Error opening word document in asp.net

Posted 27 August 2009 - 09:06 PM

The reason for that is because the document is being opened on the server that is hosting the page. ASP.NET runs server side so anything you do like this is being executed (or opened) on the server, not the clients computer. As far as I know what you're trying to do cannot be done in ASP.NET (well maybe but not without a huge amount of work)
Was This Post Helpful? 0
  • +
  • -

#7 ezzatvar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-August 09

Re: Error opening word document in asp.net

Posted 28 August 2009 - 05:22 AM

Hi,
What I want to do is open a word document and make some changes and save it.
I am using ASP.NET C#,
At the line document.Open(... program generate timeout error after a while. I can see that word process has been created from task manager, just cannot open document.
I do similar job with Excel and it works fine.
I am doing this job on my local machine, application is not deployed yet.
I am checking if file exists before document.Open().
I cannot figure out why program cannot open word file.
Does anybody have any idea what would be wrong?
Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1