0

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.

Zombo
  • 1
  • 62
  • 391
  • 407
Viktor
  • 1
  • 1
  • My test with this string formatting has no errors even with a network share formatted string in the textbox. What is exact error? – Crowcoder Aug 25 '15 at 23:29
  • Why not just use the string.Format method to help you insert the values properly instead concatenation? – idream1nC0de Aug 26 '15 at 01:54
  • @Crowcoder of course it has no errors. My problem is not that! The problem is not in Visual Studio nor in C#! The problem is that everything inside ExecuteThisJavascript() will go directly to the Acrobat Javascript engine. So for that it has to be ok too ! And it is ok, but with the given Path it will throw string errors but hard to know cause no indication where and it only shows within the Acrobat Object while it exists checking with actually opening Acrobat and the JS Debug window. Since within the C# the whole thing is late bound (no oher way from there), you don't get any info. – Viktor Aug 27 '15 at 09:03
  • @JacobHeater Again, those .NET things are not available at all in Acrobat's very limited Javascript interface. Everything inside the ExecuteThisJavascript() has to work within the Acrobat JS environment. From which you can't get any debug-worth info back to the application in .NET – Viktor Aug 27 '15 at 09:04

1 Answers1

0

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.

Crowcoder
  • 11,250
  • 3
  • 36
  • 45
  • unfortunately it is not helping :( If i do it manually in the Adobe debug console, it is fine. If like this, it fails. – Viktor Aug 29 '15 at 01:08
  • Take the variable out, hard code a string temporarily and see what happens – Crowcoder Aug 29 '15 at 11:38
  • Of course i did all these things. And many more. I will post if have any news or results. It seems like the C# handled string becomes \\\\...\\...\\ form (normal behaviour) but it goes to the Acrobat objects which can't handle the 4 \ characters. String replace before in C# didn't work... – Viktor Aug 30 '15 at 14:17
  • If i do a string replace in the app before passing to Acrobat JS, the document will display an empty form. So for the PDF itself, backslash is not working yet. – Viktor Aug 30 '15 at 16:19
  • @Viktor maybe you can try `encodeUriComponent()` – Crowcoder Aug 30 '15 at 16:28