Opening Word from .net

T

Thomas Scheiderich

I can't seem to open a word document from any of my browsers except the one
on my web server.

Here is the .aspx file:

*****************************************************************
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.IO" %>

<Script Runat="Server">

Sub Page_Load
Dim conPubs As SqlConnection
Dim cmdSelect As SqlCommand
Dim dtrAuthors As SqlDataReader

' Retrieve records from database
conPubs = New SqlConnection(
System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING
_Contour_Server"))
cmdSelect = New SqlCommand( "Select title,fullFileName From
openworx..QADocs order by title", conPubs )
conPubs.Open()
dtrAuthors = cmdSelect.ExecuteReader()

' Bind to Repeater
rptAuthors.DataSource = dtrAuthors
rptAuthors.DataBind()

dtrAuthors.Close()
conPubs.Close()
End Sub

</Script>

<html>
<head><title>Repeater.aspx</title></head>
<body>
<form Runat="Server">

<asp:Repeater
ID="rptAuthors"
Runat="Server">

<ItemTemplate>
<a href="<%# Container.DataItem("fullFileName") %>" ><%#
Container.DataItem("title") %></a><br>
</ItemTemplate>

<separatortemplate>
<hr></separatortemplate>

</asp:Repeater>

</form>
</body>
</html>
****************************************************************************
*******

This gives me a list of files from my QADocs table that generates a page
like so:

****************************************************************************
*****
<html>
<head><title>Repeater.aspx</title></head>
<body>
<form name="_ctl0" method="post" action="TMPbxwz1g6rr.aspx" id="_ctl0">
<input type="hidden" name="__VIEWSTATE" value="dDwtMjA0Nr9vNNYoX" />

<a href="c:\QA Docs\QSF 6.1.4 - Acknowledgmnt of Designated Reading.doc"
Acknowledgement of Designated Reading</a><br>

<hr>

</form>
</body>
</html>
****************************************************************************
**************

The link looks like this:

file:///c:/QA%20Docs/QSF%206.1.4%20-%20Acknowledgmnt%20of%20Designated%20Rea
ding.doc

As I said when I click on the link, a page opens up as a word document on
the web server, but not on any other workstation. It just sits there. How
do I get it to open the file?

Also, is there a way to tell the link to open up the file in a separate
window as well as to be read only?

Thanks,

Tom.
 
S

Scott Allen

Hi Tom:

To open a link in a new window, add target="_blank" as an attribute to
the href.

When you use an href like a href="c:\QA Docs\mydoc.doc", you are
telling the browser to open a docunment on the local drive C. Since
only the web server has the document on the C drive, it only works
from a browser on the server. When a remote client clicks the link the
browser tries to find the document on the remote machine's C drive.

You could keep the .doc files inside a virtual directory on your
weberver and provide a link with an HTTP URL.

HTH,
 
T

Thomas Scheiderich

Scott Allen said:
Hi Tom:

To open a link in a new window, add target="_blank" as an attribute to
the href.

That was what I was looking for.
When you use an href like a href="c:\QA Docs\mydoc.doc", you are
telling the browser to open a docunment on the local drive C. Since
only the web server has the document on the C drive, it only works
from a browser on the server. When a remote client clicks the link the
browser tries to find the document on the remote machine's C drive.

You could keep the .doc files inside a virtual directory on your
weberver and provide a link with an HTTP URL.

I was told it was dangerous to put Documents in a vitual directory as that
would leave them vulnerable. This was why I did it this way.

However, by doing this - it now works - as long as the person has Word on
his machine.

Is there a way to have the browser send the file already word formatted? If
there is no word on the machine, it displayes it as a text file which will
have all non text displayed as ascii and boxes (for non printable
characters).

Thanks,

Tom.
 
T

Thomas Scheiderich

Scott Allen said:
Hi Tom:

I think if I had to display Word as text, I would have a batch process
on the server converting Word .doc files to text files. I know there
are some third party components to do this, perhaps there are even
some free ones.

I actually didn't want to convert them to text files, just wanted to send
them already formatted to the users machine, which may not be possible (or
plauseable) - especially with the tables and images and special formatting
and spacing.
Another option you might consider is linking to the free Word document
viewer:
http://www.microsoft.com/downloads/details.aspx?FamilyID=9BBB9E60-E4F3-436D-
A5A7-DA0E5431E5C1&displaylang=EN
This looks interesting. I do remember somewhere that there was a way to put
a word document in an IFrame (which put all the normal window controls
around the Iframe. Not sure where I saw that, however.

Still can't figure out how to open the file as readonly. I suppose the only
way to do this is to actually set the file to readonly in Windows Explorer.

Thanks,

Tom.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top