Retrieve data from infopath from libraries in Sharepoint - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Retrieve data from infopath from libraries in Sharepoint

Last post 05-26-2009 08:37 PM by sathiyapriyan. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 05-14-2009 01:25 PM

    Retrieve data from infopath from libraries in Sharepoint

    Hi, I have a Sharepoint Services with a list with Infopath templates containing data. I need to take this data and process and generate a txt file in automated mode, only a front or other infopath formulary when I can choose the infopath file to process. What is the most common procedure to do this? Thank for help!
  • 05-15-2009 01:33 PM In reply to

    Re: Retrieve data from infopath from libraries in Sharepoint

    Hi all, i try this code that i found: // Get the connection to the SharePoint library
    SharepointListQueryConnection spsConn =
    (SharepointListQueryConnection)DataSources["Datasource"].QueryConnection;

    // Retrieve the name of the form from the current row
    string formName = e.Source.CreateNavigator().SelectSingleNode("@Titulo", NamespaceManager).Value;

    // Generate the URL to the form
    string formUrl = String.Format("{0}{1}/{2}", spsConn.SiteUrl, spsConn.Name, formName);

    // Get an XPathNavigator object to the GetItem method of the Copy web service
    XPathNavigator root = DataSources["GetItem"].CreateNavigator();

    // Set the Url parameter on the GetItem method
    root.SelectSingleNode("//*[local-name()='Url']").SetValue(formUrl);

    // Call the web service
    DataSources["GetItem"].QueryConnection.Execute();

    // Get the byte array stream of the form from the web service response
    XPathNavigator formStream = root.SelectSingleNode("//*[local-name() = 'Stream']");

    // Convert the base64 encoded string for the form into a byte array
    byte[] formData = Convert.FromBase64String(formStream.Value);

    /*
    Once you've converted the base64 encoded string for the form
    into a byte array, you can do whatever you like with that
    byte array. Here we will continue converting it to a string and
    then create a temporary file of that string so that we can open
    the temporary file in InfoPath.
    */

    // Convert the form's byte array into a string
    string formString = string.Empty;
    using (MemoryStream ms = new MemoryStream(formData, false))
    {
    using (StreamReader sr = new StreamReader(ms, Encoding.UTF8))
    {
    formString = sr.ReadToEnd();
    sr.Close();
    }
    ms.Close();
    }

    // Create a temporary file to write the text of the form to
    string tempFileName = Path.GetTempFileName();
    using (FileStream fs = new FileStream(tempFileName, FileMode.Open, FileAccess.ReadWrite))
    {
    using (StreamWriter sw = new StreamWriter(fs))
    {
    sw.Write(formString);
    sw.Flush();
    sw.Close();
    }
    fs.Close();
    }

    // Open the temporary file for the form in a new instance of InfoPath
    Application.XmlForms.Open(tempFileName);


    I create the datasources for get list and put GetLIst work, and i define this in code: using System.IO; using System.Text; but i got this mesage: Exception Message: Object reference not set to an instance of an object the fail in this line: string formName = e.Source.CreateNavigator().SelectSingleNode("@Titulo", NamespaceManager).Value; thanks for help
  • 05-25-2009 01:50 AM In reply to

    Re: Retrieve data from infopath from libraries in Sharepoint

    Hi Agamenon,

    If your DataSource looks like this:

    myFields
         Titulo

    Then you have to change this piece of code:


    // Retrieve the name of the form from the current row
    string formName = e.Source.CreateNavigator().SelectSingleNode("@Titulo", NamespaceManager).Value;

    With this,


    // Retrieve the name of the form from the current row
    string formName = e.Source.CreateNavigator().SelectSingleNode("/my:myFields/my:Titulo", NamespaceManager).Value

  • 05-26-2009 08:37 PM In reply to

    Re: Retrieve data from infopath from libraries in Sharepoint

    I'm using the same code nut i got an error in the line of "byte[] formData = Convert.FromBase64String(formStream.Value);" as "Object reference not set to an instance of an object".

    From this line "XPathNavigator formStream = root.SelectSingleNode("//*[local-name() = 'Stream']");" , i got the formStraem as null. why am i get like this. help needed urgently

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