Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSWord and Asp 1

Status
Not open for further replies.

staleb

Programmer
Feb 7, 2005
45
NO
I have an application that produces an word document on the server, and shows the web-link to the user.
When the user clicks this link, the word-document is opened locally on the clients computer.

I use this script to "transport" and open the the document:

<script language = vbscript>
<!--
dim s
dim objword
sub OpenDoc(strLocation)
set objWord = CreateObject("Word.Application")

objWord.Visible = true
objWord.Documents.Open strLocation
end sub
-->
</script>


On the web-server I run MSWord 2002 (this is the only one I found information about on Microsoft).


When I act as an client and log on to the web-page and try to open the word document, it works fine as long as I sit on a computer that has MSWord 2002, but when I try to do the same thing from a computer with MSWord 2003 I get this error-message:
"Object reference not set to an instance of an object"

Does anyone have a clue?
 
I had this issue in the past and it was due to the Object Model of 2002 being different to that of 2003 (we had the opposite situation though - 2003 on the machine and 2002 on the client).

It sounds like that in your case you have created the document successfully though and rather than use Documents.Open, you should just stream it to the client by redirecting them to the file and changing the Response.ContentType to msword.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Yes, the document creates successfully!

Would this soulution still make use of the clients MSWord-application?

I will try this solution that u sugested. Not quite sure how to do this, but I wil probally figure it out!

Thanks!
 
I use the following when a user needs to download a file:
Code:
    Private Sub DownloadFile(ByVal virtualPath As String)
        ' retrieve the physical path of the file to download, and create
        ' a FileInfo object to read its properties
        Dim FilePath As String = Server.MapPath(virtualPath)
        Dim TargetFile As New System.IO.FileInfo(FilePath)
        ' Check if file exists
        'Do Until System.IO.File.Exists(FilePath) = True
        'Loop
        ' Wait until file is not in use
        'Do Until isFileInUse(FilePath) = False
        'Loop
        ' clear the current output content from the buffer
        Response.Clear()
        Response.CacheControl = "Private"
        ' add the header that specifies the default filename for the Download/
        ' SaveAs dialog
        Response.AddHeader("Content-Disposition", "attachment; filename=" + _
            TargetFile.Name)
        ' add the header that specifies the file size, so that the browser
        ' can show the download progress
        Response.AddHeader("Content-Length", TargetFile.Length.ToString())
        ' specify that the response is a stream that cannot be read by the
        ' client and must be downloaded
        Response.ContentType = "application/octet-stream"
        ' send the file stream to the client
        Response.WriteFile(TargetFile.FullName)
        ' stop the execution of this page
        Response.End()
    End Sub
Note: this sets the ContentType to octet-stream so that the browser asks the user whether they would like to open or save the file. You can change this if you want to use it specifically for word files and it will do whatever the client's pc is currently set to do to word files.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Thanks!!!!!

Just one more question!
When I do this "Download/save"
Can the user edit the document and save it back to its original path?

U see I neeed the document to be avilable from any computer that logs on the web-page?
 
>>When I do this "Download/save"
Can the user edit the document and save it back to its original path?


Yes. if he has saved the file to the system then it becomes just like any normal file...

Known is handfull, Unknown is worldfull
 
As vbkris says the user can just save the file and then you can use a HtmlInputFile to allow them to upload it back to the site.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Hi again

Excuse my lack of knowlegde here on this topic.

But is this the right assumption regarding, download file and HtmlInputFile:

The user need to download the file
make the changes
store it locally
and then upload it?

Is this correctly understood?


My idea with this application was that the user can open the document directly from the server make changes on the document and then save it. (Just like he was working on a local document)

I realize now that this would have to mean that the user have directly access to the web-server file-folder (where the documents is stored)


Thanks for the answers so far.
 
But is this the right assumption regarding, download file and HtmlInputFile:

The user need to download the file
make the changes
store it locally
and then upload it?

Is this correctly understood?
Your assumptions are correct. This would have been my preferred method if I needed to do the same task.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
>>My idea with this application was that the user can open the document directly from the server make changes on the document and then save it. (Just like he was working on a local document)


not possible. (u may use workarounds like providing a word like interface online. look for "RichText Editors")...

Known is handfull, Unknown is worldfull
 
I really appricate all the ansewers given
One final question.

This "Private Sub DownloadFile" routine does it require the document to stored on the web server.

The reaseon I ask is this.

We have three servers: One DB, one document server and one web-server.

Our users only have access to the web-server through html.
Will they be able to reach the files on the documents.
The web-server have full connection with the two other servers. And then "virtualPath" is a path to the document server.


I'm asking because as usally it works fine with my developing pc, which can comunicate with all three servers, but when I try it from one of our users computers I get: "This page cant be displayed"

Hope this was written so that it came out understandably :)

 
>>This "Private Sub DownloadFile" routine does it require the document to stored on the web server.

Yes.

>>Private Sub DownloadFile(ByVal virtualPath As String)
ByVal virtualPath As String - path of the file...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top