Fire vb-script from code, Syntax-error

Posted on 2007-07-31
Last Modified: 2010-04-15
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(" \")\n ");
               sb.Append("</script> \n");
this.Page.RegisterStartupScript("Open", sb.ToString());
Question by:staleb
    LVL 96

    Expert Comment

    by:Bob Learned
    You don't need to do this to use Word with ASP.NET.

    Microsoft Word Documents from ASP.NET


    Author Comment

    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
    LVL 96

    Accepted Solution

    Try using Environment.NewLine instead of \n:

     sb.Append("\n<script language=vbscript >" + Environment.NewLine);


    Author Comment

    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

    Author Comment

    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.. :)

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now