Link to home
Start Free TrialLog in
Avatar of staleb
staleb

asked on

Fire vb-script from code, Syntax-error

I'm getting a Syntax error in the Internet explorer when I'm trying to fire a vb script from code.
I have coppied the script from an old vb-project, but I must be translating it wrong.
Can anyone help me?

StringBuilder sb = new StringBuilder("");
               sb.Append("\n<script language=vbscript >\n");
               sb.Append("  Dim Word \n");
               sb.Append("  Dim Doc \n");
               sb.Append("Set Word = CreateObject(\"Word.Application\")\n");
               sb.Append("Set Doc = CreateObject(\"Word.Document\")\n ");
               sb.Append("Word.Visible = True \n");
               sb.Append("Set Doc = Word.Documents.Open(\"");
               sb.Append(fileName.ToString());
               sb.Append(" \")\n ");
               sb.Append("Doc.SaveAs(\"");
               sb.Append(fileNameLocal);
               sb.Append("\")\n");
               sb.Append("</script> \n");
this.Page.RegisterStartupScript("Open", sb.ToString());
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

You don't need to do this to use Word with ASP.NET.

Microsoft Word Documents from ASP.NET
http://www.codeproject.com/aspnet/wordapplication.asp

Bob
Avatar of staleb
staleb

ASKER

I'm not sure thisis the solution
Since this is a web application, And I don't want the users to use Wordl server-side. But I want them to use their local MSWord so that they can edit the document.
If I use a document stored server-side, it will come up write-protected
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of staleb

ASKER

Here is the script I'm trying to "translate"
script = "<script language=""vbscript"">" & vbCrLf

                script &= "  Dim Word" & vbCrLf
                script &= "  Dim Doc" & vbCrLf
               script &= "  Set Word = CreateObject(""Word.Application"") " & vbCrLf
                script &= "  Set Doc = CreateObject(""Word.Document"") " & vbCrLf
                script &= "  Word.Visible = True" & vbCrLf
                script &= "  set Doc = Word.Documents.Open(""" & sDokNavn.ToString & """) " & vbCrLf
                script &= "  Doc.SaveAs(""" & sDokNavnLokalt & """)" & vbCrLf
                script &= "</script>" & vbCrLf
Avatar of staleb

ASKER

Finally Made it work
Added + Environment.NewLine and altered some security settings in the browser and it worked.
Not quite sure what was the trigger that made it work, but it does work so.. :)