C# verbatim string insert to Acrobat Javascript

191 Views Asked by At

I have a syntax error and i can't solve it at the moment. Task: C# app with Acrobat JS Invoke... I pass this as a string command:

acrofields.ExecuteThisJavascript(@"this.getField(""TM"").value = """ + TM_Textbox.Text + @""";");

I use verbatim string to make my life easier in other situations (similar to this). So as you can see the textbox content has to be in "" as well. And this works fine! BUT: If i have a Path as content:

\\\Computername\Folder1\Folder2\\...

it won't work. I have tried many possibilities of the quoting.

1

There are 1 best solutions below

5
On

Since it is JavaScript that will be executed, turn your internal quotes into single quotes:

acrofields.ExecuteThisJavascript(@"this.getField('TM').value = '" + TM_Textbox.Text + @"';");

or, better yet:

string execStr = string.Format("this.getField('TM').value = '{0}';", TM_TextBox.Text);
acrofields.ExecuteThisJavascript(execStr);

Of course, you also probably want to sanitize the textbox input to prevent malicious script attacks.