thisxdocument error - InfoPath Dev Sign in | Join | Help in Code InfoPath (Entire Site) InfoPath Dev InfoPath Dev is dedicated to bringing you the information and tools you need to be successful in your Microsoft Office InfoPath development projects. Home Blogs Forums Photos Downloads InfoPath Dev » InfoPath » Code » thisxdocument error thisxdocument error Last post 01-17-2009 08:51 AM by Jimmy. 15 replies. Page 1 of 2 (16 items) 1 2 Next > Sort Posts: Oldest to newest Newest to oldest Previous Next 12-11-2008 05:00 AM BuildPro Guru Joined on 02-27-2008 Beavercreek, Ohio, USA Posts 77 thisxdocument error Reply Contact Alrighty then.....I am trying to get the current username and stick it in a field on my form. I have IP 2007 and wss 2.0. I do not have access to the server to install the AD Webservice (how wonderful that would be) so I am trying this 'freelance'. This is what I have been able to dig up in C#: thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/@ALCOUN").text = System.Environment.UserName; When I build the code, I get this error: The name 'thisXDocument' does not exist in the current context. I have tried 90 (well, maybe only 10 or so) ways from Sunday and I cannot figure it out. Keep in mind that I don't know alot about writing C#, therefore, I cut and paste just about all of my code and then tweak it to fit my solution. Fishman 12-11-2008 05:30 AM In reply to Anuma Joined on 07-20-2005 India Posts 525 Re: thisxdocument error Mark as Not AnswerMark as Answer... Reply Contact Hi, Thisxdocument will not work in the infopath2007. Can you try below code. XPathNavigator xn = this.MainDataSource.CreateNavigator(); XPathNavigator xnUserName = xn.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/@ALCOUN", this.NamespaceManager); string currentUser = System.Environment.UserName.ToString(); xnUserName.SetValue(currentUser); Anuma Chinthapalli /http://www.GGKTech.com 12-11-2008 05:55 AM In reply to Jimmy Joined on 07-03-2008 Posts 2,595 Re: thisxdocument error Mark as Not AnswerMark as Answer... Reply Contact If you would like to try programming with the InfoPath 2003 object model and try out the code involving thisXDocument that you seem to be finding, you can switch to that by going to Tools->Form Options->Programming, clicking Remove Code and selecting C# (2003 Object Model). Jimmy Rishe / Software Developer / Microsoft MVPQdabra Software 12-11-2008 06:03 AM In reply to BuildPro Guru Joined on 02-27-2008 Beavercreek, Ohio, USA Posts 77 Re: thisxdocument error Mark as Not AnswerMark as Answer... Reply Contact Hello Anuma and thank you for your response. I tried the code you provided and I got this error: System.Security.SecurityException was unhandled by user code Message="Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed." Source="mscorlib" StackTrace: at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessPermission.Demand() at System.Environment.get_UserName() at Customer_Care___no_code.FormCode.FormEvents_Loading(Object sender, LoadingEventArgs e) at Microsoft.Office.InfoPath.Internal.FormEventsHost.OnLoad(DocReturnEvent pEvent) at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent) Is this telling me that I need to set my form to full trust? That isn't possible for me. Is there another way? Fishman 12-11-2008 06:04 AM In reply to BuildPro Guru Joined on 02-27-2008 Beavercreek, Ohio, USA Posts 77 Re: thisxdocument error Mark as Not AnswerMark as Answer... Reply Contact Hello Jimmy. I can't use the 2003 OM as I have a ton of code that requires C#. Fishman 12-11-2008 06:12 AM In reply to Jimmy Joined on 07-03-2008 Posts 2,595 Re: thisxdocument error Mark as Not AnswerMark as Answer... Reply Contact You can use C# with the 2003 OM (note my previous post saying to select "C# (2003 Object Model)". But the 2007 one is just as good, if not better. My guess is that you are getting that error because of this line: System.Environment.UserName; Your form probably needs to be full trust to access System.Environment, but you should be able to get the user name by setting up a rule to copy the value of the userName() function to a field and then querying that field from the code. Jimmy Rishe / Software Developer / Microsoft MVPQdabra Software 12-11-2008 06:21 AM In reply to BuildPro Guru Joined on 02-27-2008 Beavercreek, Ohio, USA Posts 77 Re: thisxdocument error Mark as Not AnswerMark as Answer... Reply Contact Sorry about the confusion on the 2003 thing. I have to use strictly C# - no 2003 OM. Is it possible to do without full trust? Full trust is not an option. Too many complications in my deployment - we are on an intranet/extranet without VPN or anything - no certificates, etc. "Your form probably needs to be full trust to access System.Environment, but you should be able to get the user name by setting up a rule to copy the value of the userName() function to a field and then querying that field from the code." Not sure that I am following you here. I dont think that I am able to get the username before it throws the security error. Fishman 12-11-2008 06:38 AM In reply to Jimmy Joined on 07-03-2008 Posts 2,595 Re: thisxdocument error Mark as Not AnswerMark as Answer... Reply Contact Remove the line that uses System.Environment.UserName from your code Place a button on the form in the designer. Double-click the button. Click Rules... Click Add... Click Add action... Select "Set a field's value" Select the /dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/@ALCOUN field Click the fx button Click Insert function... Select "All" Scroll down and Select userName Click OK 6 times. Jimmy Rishe / Software Developer / Microsoft MVPQdabra Software 12-11-2008 06:51 AM In reply to BuildPro Guru Joined on 02-27-2008 Beavercreek, Ohio, USA Posts 77 Re: thisxdocument error Mark as Not AnswerMark as Answer... Reply Contact Sorry to be dense....if my code is like this: XPathNavigator xn = this.MainDataSource.CreateNavigator(); XPathNavigator xnUserName = xn.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/@ALCOUN", this.NamespaceManager); xnUserName.SetValue(currentUser); I get build errors: the name 'CurrentUser' does not exist in the curretn context. if my code looks like this: XPathNavigator xn = this.MainDataSource.CreateNavigator(); XPathNavigator xnUserName = xn.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/@ALCOUN", this.NamespaceManager); The build works, but nothing happens in the form. Fishman 12-11-2008 06:57 AM In reply to BuildPro Guru Joined on 02-27-2008 Beavercreek, Ohio, USA Posts 77 Re: thisxdocument error Mark as Not AnswerMark as Answer... Reply Contact Nevermind. I fixed it. I set this: xnUserName.SetValue(currentUser); to this: xnUserName.SetValue("/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/@ALCOUN "); and it worked fine. Thanks a bunch for the help! Fishman 12-11-2008 07:09 AM In reply to Jimmy Joined on 07-03-2008 Posts 2,595 Re: thisxdocument error Mark as Not AnswerMark as Answer... Reply Contact Thank you, but all that code does is assign the value "/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/@ALCOUN " to that field. I'm pretty sure that if all you want to do is assign the user name to that field you can use a rule the way I described and skip using code altogether. Jimmy Rishe / Software Developer / Microsoft MVPQdabra Software 12-11-2008 07:20 AM In reply to BuildPro Guru Joined on 02-27-2008 Beavercreek, Ohio, USA Posts 77 Re: thisxdocument error Mark as Not AnswerMark as Answer... Reply Contact You have got to be kiddiing me. I have been fooling around with this for hours and the rule works all by itself. Sometimes I can be an idiot. Thanks again for all your help and have a Merry Christmas! Fishman 12-11-2008 07:38 AM In reply to Jimmy Joined on 07-03-2008 Posts 2,595 Re: thisxdocument error Mark as Not AnswerMark as Answer... Reply Contact Don't worry about it. This InfoPath stuff can be tough to get used to but I can say from experience that it all starts to come together sooner or later. I'm glad I was able to help. A Merry Christmas to you too! Jimmy Rishe / Software Developer / Microsoft MVPQdabra Software 01-15-2009 09:18 AM In reply to StepStep Joined on 01-15-2009 Posts 2 Re: thisxdocument error Mark as Not AnswerMark as Answer... Reply Contact I seem to have a great big problem with Web-enabled forms. Not only is the thisXDocument property not available, it seems impossible to get a reference to an XDocument from the Application. I am using Infopath 2007 with VS2008 and MOSS 2007.Data sources are web services with query parameters. I want to select a value from a drop-down list (which I can, and it is ok) through this code:public void fldBusinessUnit_Changed(object sender, XmlEventArgs e) {int index; XPathNavigator nav = MainDataSource.CreateNavigator();string val = nav.SelectSingleNode("/my:ceaFormFields/my:mainGroup/my:fldBusinessUnit", NamespaceManager).Value;if (Int32.TryParse(val, out index)) { WebServiceConnection conn = (WebServiceConnection )DataConnections["GetApproversByBusinessUnitNumber"];if (!String.IsNullOrEmpty(conn.Name)) { //etc. } and then I want to set a query parameter on a web data source. I have tried this code and it works, but I cannot seem to get the display control to update. I can't seem to be able to assign an XMLDocument to it as a datasource: // Create XmlDocuments.XmlDocument inputDocument = new XmlDocument(); XmlDocument outputDocument = new XmlDocument();XmlDocument errorsDocument = new XmlDocument(); // Load input document.inputDocument.LoadXml(string.Concat("<?xml version=\"1.0\" encoding=\"utf-8\" ?><Number>", index.ToString(), "</Number>")); // Create XPathNavigator objects for documents.XPathNavigator inputNav = inputDocument.CreateNavigator(); XPathNavigator outputNav = outputDocument.CreateNavigator(); XPathNavigator errorsNav = errorsDocument.CreateNavigator(); // Call Execute method. conn.Execute(inputNav, outputNav, errorsNav); // how do I get these data into a repeater control? How do I get the form to update? Any help will be much, much appreciated! Thanks, Step van Schalkwyk Filed under: web service, XDocument, query parameter, Infopath 2007 01-15-2009 09:19 AM In reply to StepStep Joined on 01-15-2009 Posts 2 Re: thisxdocument error Mark as Not AnswerMark as Answer... Reply Contact Jimmy, would you take a look at my question following this one please? Much appreciated! Thanks, Step. Page 1 of 2 (16 items) 1 2 Next > Copyright © 2003-2019 Qdabra Software. All rights reserved.View our Terms of Use.
Alrighty then.....I am trying to get the current username and stick it in a field on my form. I have IP 2007 and wss 2.0. I do not have access to the server to install the AD Webservice (how wonderful that would be) so I am trying this 'freelance'. This is what I have been able to dig up in C#:
thisXDocument.DOM.selectSingleNode(
When I build the code, I get this error:
The name 'thisXDocument' does not exist in the current context.
I have tried 90 (well, maybe only 10 or so) ways from Sunday and I cannot figure it out. Keep in mind that I don't know alot about writing C#, therefore, I cut and paste just about all of my code and then tweak it to fit my solution.
Hi,
Thisxdocument will not work in the infopath2007. Can you try below code.
XPathNavigator xn = this.MainDataSource.CreateNavigator(); XPathNavigator xnUserName = xn.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/@ALCOUN", this.NamespaceManager);
string currentUser = System.Environment.UserName.ToString(); xnUserName.SetValue(currentUser);
If you would like to try programming with the InfoPath 2003 object model and try out the code involving thisXDocument that you seem to be finding, you can switch to that by going to Tools->Form Options->Programming, clicking Remove Code and selecting C# (2003 Object Model).
Hello Anuma and thank you for your response. I tried the code you provided and I got this error:
System.Security.SecurityException was unhandled by user code Message="Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed." Source="mscorlib" StackTrace: at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessPermission.Demand() at System.Environment.get_UserName() at Customer_Care___no_code.FormCode.FormEvents_Loading(Object sender, LoadingEventArgs e) at Microsoft.Office.InfoPath.Internal.FormEventsHost.OnLoad(DocReturnEvent pEvent) at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent)
Is this telling me that I need to set my form to full trust? That isn't possible for me. Is there another way?
Hello Jimmy. I can't use the 2003 OM as I have a ton of code that requires C#.
You can use C# with the 2003 OM (note my previous post saying to select "C# (2003 Object Model)".
But the 2007 one is just as good, if not better. My guess is that you are getting that error because of this line:
System.Environment.UserName;
Your form probably needs to be full trust to access System.Environment, but you should be able to get the user name by setting up a rule to copy the value of the userName() function to a field and then querying that field from the code.
Sorry about the confusion on the 2003 thing. I have to use strictly C# - no 2003 OM. Is it possible to do without full trust? Full trust is not an option. Too many complications in my deployment - we are on an intranet/extranet without VPN or anything - no certificates, etc.
"Your form probably needs to be full trust to access System.Environment, but you should be able to get the user name by setting up a rule to copy the value of the userName() function to a field and then querying that field from the code."
Not sure that I am following you here. I dont think that I am able to get the username before it throws the security error.
Sorry to be dense....if my code is like this:
xnUserName.SetValue(currentUser);
I get build errors:
the name 'CurrentUser' does not exist in the curretn context.
if my code looks like this:
The build works, but nothing happens in the form.
Nevermind. I fixed it. I set this:
to this:
xnUserName.SetValue("/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/@ALCOUN ");
and it worked fine. Thanks a bunch for the help!
Thank you, but all that code does is assign the value "/dfs:myFields/dfs:dataFields/d:Buyers/d:WorkOrders/@ALCOUN " to that field.
I'm pretty sure that if all you want to do is assign the user name to that field you can use a rule the way I described and skip using code altogether.
You have got to be kiddiing me. I have been fooling around with this for hours and the rule works all by itself. Sometimes I can be an idiot. Thanks again for all your help and have a Merry Christmas!
Don't worry about it. This InfoPath stuff can be tough to get used to but I can say from experience that it all starts to come together sooner or later. I'm glad I was able to help.
A Merry Christmas to you too!
I seem to have a great big problem with Web-enabled forms. Not only is the thisXDocument property not available, it seems impossible to get a reference to an XDocument from the Application.
I am using Infopath 2007 with VS2008 and MOSS 2007.Data sources are web services with query parameters.
I want to select a value from a drop-down list (which I can, and it is ok) through this code:
{
{ //etc. }
and then I want to set a query parameter on a web data source.
I have tried this code and it works, but I cannot seem to get the display control to update. I can't seem to be able to assign an XMLDocument to it as a datasource:
// Create XmlDocuments.
conn.Execute(inputNav, outputNav, errorsNav); // how do I get these data into a repeater control? How do I get the form to update?
Any help will be much, much appreciated!
Thanks,
Step van Schalkwyk
Jimmy, would you take a look at my question following this one please?
Much appreciated!
Step.