Hi there!
Wow, you have a lot of different languages going on. To start with, it looks as if you are using VB.NET, but did you know that the double slashes are a comment mark for C#? So your line:
Me.CurrentView.Export("C:\MyView.pdf", ExportFormat.Pdf) //VB-Code
won't compile, because of the "//VB-Code" at the end of it -- the compiler doesn't know what to do! And later, it looks like you have a jscript sample, but for some reason it also has the "//VB-Code" comment in it. Fortunately, "//" is a comment mark in jscript, but if you try to mix jscript with your VB.NET, you will continue to have issues.
First, let's talk about how to find out what language your form is using and how to reset it if necessary. For IP 2007, go to Tools/Form Options/Programming. There you will be able to at least see what language the form is set to. If you want to change it, click the Remove Code button. Keep in mind the buton does what it says -- it will remove all existing code. Also, you say you are using IP 2007, but the OnClick event belongs to the IP 2003 object model. You may want to remove your code and select either Visual Basic or C# for your language, as the samples I'm about to give you use the 2007 object model.
You'll need to add an event handler for your button after removing your code. Right click on your button and select Button Properties. Be sure the Action is set to Rules and Custom Code. Give your button a meaningful ID and select Edit Form Code. This will add an event handler for your button. In the following samples, my button's ID is Print. The first line of your code will vary according to your button ID.
Now to what you want to do. You are correct that the form will have to be full trust and that you need the add in. Here is a VB.NET sample that exports to pdf and uses the name of a field for the file name:
Public Sub Print_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs) 'Declare our variable
Dim fileName As String
Dim nameNode As XPathNavigator
'Set the values. Replace "/my:myFields/my:textField" with the xpath to the field that has the value you want as the file name
nameNode = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:textField", NamespaceManager)
fileName = nameNode.Value + ".pdf" 'Do the work -- notice we use the variable fileName as part of the path for the file
Me.CurrentView.Export("C:\" + fileName, ExportFormat.Pdf)
End Sub
And here is C#:
public void Print_Clicked(object sender, ClickedEventArgs e)
{
//Declare our variables
string fileName;
XPathNavigator nameNode;
//Set the values. Replace "/my:myFields/my:textField" with the xpath to the field that has the value you want as the file name
nameNode = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:textField", NamespaceManager);
fileName = nameNode.Value + ".pdf"; //Do the work -- notice we use the variable fileName as part of the path for the file.
this.CurrentView.Export(@"C:\" + fileName, ExportFormat.Pdf);
}
I'll upload the samples I did to our "Basic Stuff" section in the downloads -- you'll be able to find them here if you need them, okay? Let me know if you need more help.