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());
stalebAsked:
Who is Participating?
 
Bob LearnedConnect With a Mentor Commented:
Try using Environment.NewLine instead of \n:

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

Bob
0
 
Bob LearnedCommented:
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
0
 
stalebAuthor Commented:
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
0
 
stalebAuthor Commented:
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
0
 
stalebAuthor Commented:
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.. :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.