How Do I open doc, xls, ppt as read-only using Javascript

I am creating a server side application using VB.Net.  I can succesfully open doc, xls, and ppt using the posted code below.  This is fine when the application is accessed by the author creating the doc, xls, or ppt.  How do I add in a read-only attribute for other users?  Note I already have the appropriate code to catch the author/other users, I just need to know if it is possible to open the files in read-only through javascript.

If dr("T_Path").ToString.EndsWith(".xls") Then
                Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf)
                Response.Write("var w = new ActiveXObject('Excel.Application');" & vbCrLf)
                Response.Write("var obj;" & vbCrLf)
                Response.Write("w.Visible=true;" & vbCrLf)
                Response.Write("obj=w.Workbooks.Open(""" & dr("T_Path").ToString & """)" & vbCrLf)
                Response.Write("</script>")
            End If
            If dr("T_Path").ToString.EndsWith(".doc") Then
                Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf)
                Response.Write("var w = new ActiveXObject('Word.Application');" & vbCrLf)
                Response.Write("var docText;" & vbCrLf)
                Response.Write("var obj;" & vbCrLf)
                Response.Write("w.Visible=true;" & vbCrLf)
                Response.Write("obj=w.Documents.Open(""" & dr("T_Path").ToString & """)" & vbCrLf)
                Response.Write("</script>")
            End If
            If dr("T_Path").ToString.EndsWith(".ppt") Then
                Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf)
                Response.Write("var w = new ActiveXObject('PowerPoint.Application');" & vbCrLf)
                Response.Write("w.Visible=true;" & vbCrLf)
                Response.Write("obj=w.Presentations.Open(""" & dr("T_Path").ToString & """)" & vbCrLf)
                Response.Write("</script>")

Open in new window

LVL 1
Black_FlagAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT ExpertCommented:
These say no

http://p2p.wrox.com/topic.asp?TOPIC_ID=43487

These say yes:

http://www.codeprof.com/dev-archive/209/10-32-2092996.shtm

Open(FileName:="C:\Test.doc", ReadOnly:=True)
0
-sg-Commented:
First try changing this line:

Response.Write("obj=w.Workbooks.Open(""" & dr("T_Path").ToString & """)" & vbCrLf)

to

Response.Write("obj=w.Workbooks.Open(""" & dr("T_Path").ToString & """, null, true);" & vbCrLf)

If that doesnt work then try changing it to:

Response.Write("obj=w.Workbooks.Open(""" & dr("T_Path").ToString & """, null, false, null, null, null, true);" & vbCrLf)

Those extra parameters of the Open method control things like read-only mode.

If they dont work then I'm out of ideas for now.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Michel PlungjanIT ExpertCommented:
so try

<script type="text/javascript">
<%
Response.Write("var path =  '"& dr("T_Path").ToString & "';" & vbCrLf)
%>
var appls = { xls: "Excel.Application", doc: "Word.Application", ppt: "PowerPoint.Application"}
var colls = { xls: "Workbooks", doc: "Documents", ppt: "Presentations"}
var ext = (path)?path.substring(path.lastIndexOf('.')+1):"";
if (ext && appls[ext]) {
  var obj;
  var w = new ActiveXObject(appls[ext]);
  w.Visible=true;
  obj=w[colls[ext]].Open(path,"ReadOnly=true");
}
</script>

Open in new window

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Michel PlungjanIT ExpertCommented:
or if -sg- has the correct syntax,

change
 obj=w[colls[ext]].Open(path,"ReadOnly=true");
to
 obj=w[colls[ext]].Open(path,null,true);
0
Black_FlagAuthor Commented:
-sq- The following opened .doc and .xls in read only:

Response.Write("obj=w.Workbooks.Open(""" & dr("T_Path").ToString & """, null, true);" & vbCrLf)

However it didn't work for the .ppt files.  I also tried your other example and that didn't work either.
Microsoft Power Point opens, but the actual presentation does not open in read only:

Response.Write("obj=w.Presentations.Open(""" & dr("T_Path").ToString & """,null,true);" & vbCrLf)

When I take out the [,null, true] it opens but with read/write permissions.

Any ideas for .ppt files?

mplungjan - I am going to try your code example for the ppt files to see if it works.  I will respond back with what I get.
0
Michel PlungjanIT ExpertCommented:
If it does not work using -sg-'s suggestions I am not sure my suggestion would be any better...

I see here that the frist parameter is readonly flag, so perhaps

 obj=w[colls[ext]].Open(path,true);

In any case here it is:
<script type="text/javascript">
<%
Response.Write("var path =  '"& dr("T_Path").ToString & "';" & vbCrLf)
%>
var appls = { xls: "Excel.Application", doc: "Word.Application", ppt: "PowerPoint.Application"}
var colls = { xls: "Workbooks", doc: "Documents", ppt: "Presentations"}
var ext = (path)?path.substring(path.lastIndexOf('.')+1):"";
if (ext && appls[ext]) {
  var obj;
  var w = new ActiveXObject(appls[ext]);
  w.Visible=true;
  obj=w[colls[ext]].Open(path,true);
}
</script>

Open in new window

0
Black_FlagAuthor Commented:
mplungjan - i tried that and it didnt work for my .ppt files.

Any other ideas?
0
Michel PlungjanIT ExpertCommented:
I really looked. It is impossible to find the proper syntax for the Presentations.open but I saw false, false, true and such so perhaps you can just try adding parms
0
Black_FlagAuthor Commented:
mplungjan - The following worked for .ppt files - used false instead of null like you said-

Response.Write("obj=w.Presentations.Open(""" & dr("T_Path").ToString & """,false,true);" & vbCrLf)

Thank you both for your help.
0
Michel PlungjanIT ExpertCommented:
So you did not feel for using the smaller script I made for you?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.