Infopath 2007 Visual Studio 2008, .NET 3.5, C#
Hi, I'm new on C# and Infopath 2007.
I'm trying to write code in FormEvents_Loading to check if the current form is new (not previously saved) but I can not use the examples I find on web:
public
partial class FormCode
{
private Microsoft.Office.Interop.InfoPath.SemiTrust.XDocument thisXDocument;
private Microsoft.Office.Interop.InfoPath.SemiTrust.Application thisApplication;
void FormEvents_Loading(object sender, LoadingEventArgs e)
{
if (thisXDocument.IsNew == true)
{
//Some code...
}
}
}
When previewing the template there is a NullReferenceException saying "Object reference not set to an instance of an object".
According to the information i've found on the web there should be an auto generated _Startup event where the thisXDocument variable should be initialized but I do not have such an event at all. If I add such an event like below it's never even called and I get the same exception. There is a Startup event on the other hand but I can't see how I could use it.
public void _Startup(Application app, XDocument doc)
{
thisXDocument = doc;
thisApplication = app;
}
/Lars