SecondaryDataSource - How to access ? - InfoPath Dev
in

InfoPath Dev

SecondaryDataSource - How to access ?

Last post 07-14-2009 11:48 AM by ccarns. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 07-13-2009 01:12 AM

    SecondaryDataSource - How to access ?

    Well, i know how to access within my 'CodeBehind' to the MainDataSources of the InfoPath Formular...

    MainDataSource. xyz ...

    But how to access the SecondaryDataSources ?

    SecondaryDataSource as Class or Object doesnt exist.

    And if i am already bother you with my question, i would be pleased if someone could explain to me how to create a SecondaryDataSource with CodeBehind. For example, you push a Button and a XML File will be connected which will perform as DataSource. The Fields wont change, only the Data itself.

  • 07-13-2009 01:25 AM In reply to

    Re: SecondaryDataSource - How to access ?

     You can access the secondary data sources by using the DataSources collection, like this:

    DataSources["nameOfSource"]

    So if I wanted to create an XPathNavigator to a data source called Weevils, I would use:

    DataSources["Weevils"].CreateNavigator()

    I'm not sure what to say for your second question.  I don't fully understand it and I have a feeling that there may not be a way to do what you want.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-13-2009 01:34 AM In reply to

    Re: SecondaryDataSource - How to access ?

    Thanks for your fast answer, about the second question.

    I think about if there is a way to create in real time (while the InfoPath form is open) new Secondary Connection, or even better, refresh a existing one. (XML retrieving DataSource, - only the URL had to be refreshed).

  • 07-13-2009 05:32 AM In reply to

    • danirrivas
    • Not Ranked
    • Joined on 07-13-2009
    • Barcelona, Spain
    • Posts 6

    Re: SecondaryDataSource - How to access ?

    You can refresh a secondary data connection from code using the command Execute, something like this: 

    XPathNavigator documentWhere = this.DataSources["yourSecondaryDataSource"].CreateNavigator();

    XPathNavigator fieldWhere = documentWhere.SelectSingleNode("/dfs:myFields/dfs:queryFields/ns1:GetItem/ns1:WhereCondition", this.NamespaceManager);

    fieldWhere.SetValue("Here goes the query");

    this.DataSources["yourSecondaryDataSource"].QueryConnection.Execute();

     

    Hope it helps :-)

  • 07-14-2009 01:57 AM In reply to

    Re: SecondaryDataSource - How to access ?

    Hi danirrivas,

    thanks also for your answer, but i have still one question which confuse me a lot. You are selecting within your SecondaryDataConnection a Field with the XPATH:

    ("/dfs:myFields/dfs:queryFields/ns1:GetItem/ns1:WhereCondition",)

    sure, this is only a example... but in my own SecondaryDataConnection i dont have any field which would fit a "where" condition , or even the String i must enter into InfoPath for the XML. So this wont work, or is there a way to "always" set a Where Field in every XML Query? i will keep searching, and try to find a possible way to modifiy the xml shema that there will be a working "where" condition. Maybe there is one.

    My Current XML Recieving DataConnection is: http://servername/sites/germansite/Docs/_vti_bin/owssvr.dll?Cmd=Display&List={LISTID}&View={VIEWID}&XMLDATA=TRUE&FilterField1=InternalFieldName&FilterValue1=FieldValueToFilter

    If possible i would edit this string in real time, but good to know that there is also a way to work directly in the XML DataSource.

  • 07-14-2009 04:14 AM In reply to

    Re: SecondaryDataSource - How to access ?

     Hello again,

     It looks like you can accomplish what you want to do with some code like the following:

                FileQueryConnection q = DataSources["dataSourceName"].QueryConnection as FileQueryConnection;
                q.FileLocation = "address to XML file";
                q.Execute();

    Then that data source should have the contents of the XML file you indicated.  You still have to do this on an existing data connection (that is, you can't create a new one at runtime, but you can switch out the XML file).

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-14-2009 04:56 AM In reply to

    Re: SecondaryDataSource - How to access ?

    Thanks a lot Jimmy, works perfect, fast and was really easy to implement in the current form. 

    Its good to know that there is a place where you can get answers around InfoPath if there are Problems/Questions.

  • 07-14-2009 11:48 AM In reply to

    • ccarns
    • Not Ranked
    • Joined on 06-26-2009
    • Posts 9

    Re: SecondaryDataSource - How to access ?

    Be forwarned that this technique does not work on a web enabled form. So if your end goal is to have people fill it out who do not have infopath then you will need to use a workaround.

Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.