Extracting data from infopath fields or extracting metadata from .xsn - InfoPath Dev
in

InfoPath Dev

Extracting data from infopath fields or extracting metadata from .xsn

Last post 08-20-2009 12:41 AM by Qazi Anis. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-16-2009 06:04 AM

    Extracting data from infopath fields or extracting metadata from .xsn

    Hello,

     I'm looking into infopath functionallity looking to use it in a system with MS form server and sharepoint, a viewer is also used to show the form on a webpage, my problem is that I would like to  encrypt som of the data before sending the form.
    Reading information and trying to understand how this setup will work I've looked into two different solutions. I hope mabey you can give me some help and direction if this is possible.

    As I've understood there is no way to encryption module in infopath. Possible solutions here could be to:

    1) take the data from the fields locally, encrypt the data and put them back in the form to send the data to the database.
    2) Take the data from the fields locally, encrypt the data and send them trought another channel to the database where I store the final data.

    Are any of these viable at all?

    Mabey this other question is kind of offtopic but still wondering and mabey you can help me or guide me in the right direction.
    Is it possible to extract the question data and the metadata for a question & answering field from the .xsn file and be able to interpet this in any other program then form server? Would also then be interested in extracting some cind of validation rules also.
    Thinking about making some code of my own to handle the fields that I want to be encrypted, but then I guess I need to be able to mark the fields in a specific way. Is there support for marking fields in such a way and to extract the information 

     

     Thx in advance for any help.

     

    - martin
  • 07-23-2009 08:32 AM In reply to

    Re: Extracting data from infopath fields or extracting metadata from .xsn

    Hi Martin,

    I can't comment on the encryption part, but it's certainly possible to access the form data from within SharePoint.

    For your submitted forms, the SPListItem.File object gives you access to the actual XML form that holds the data.

    The easiest way to use is is to save your .xsn as source, then use xsd.exe to create a class from it.  You can then deserialise the XML in code to an instance of your class...

    E.g., Use xsd.exe /c to create a class called myForm, then use the following code in SharePoint to get the data from a listitem called listItem:

    XmlSerializer serialiser = new XmlSerializer(typeof(myForm));

    using (System.IO.StreamReader reader = new System.IO.StreamReader(listItem.File.OpenBinaryStream()))
    {
    myForm formData = (
    myForm)serialiser.Deserialize(reader);
    }

    You can then access the data with formData.SomeElement, etc.  xsd.exe is available at the Visual Studio command prompt.

    Craig

  • 07-23-2009 11:31 PM In reply to

    Re: Extracting data from infopath fields or extracting metadata from .xsn

    Hello Craig,

     Thx for your answer.

    Not sure if I was clear enough, because  I need a way to grab the data before they are stored in any way. They way I understad your code you fetch the data from the .xml file that the data is stored in after the form has been submitted?

     

    - martin
  • 08-20-2009 12:41 AM In reply to

    Re: Extracting data from infopath fields or extracting metadata from .xsn

    hello Martinas,

    well you can encrypt the data in the infopath form before saving or submiting it

    below is the code to encrypt a field in InfoPath 2007.

                 Rijndael rKey = new RijndaelManaged();
                XPathNavigator xnFormName = null;
                XPathNavigator totalNode = this.MainDataSource.CreateNavigator();

                xnFormName = totalNode.SelectSingleNode("/my:myFields/my:field1", this.NamespaceManager);

                string totalNodeOriginal = xnFormName.ToString();
                byte[] totalInfo =
                    System.Text.Encoding.Unicode.GetBytes(xnFormName.ToString());
                MemoryStream ms = new MemoryStream();
                CryptoStream csBase64 = new CryptoStream(ms,
                     new ToBase64Transform(), CryptoStreamMode.Write);
                CryptoStream csRijndael = new CryptoStream(csBase64,
                     rKey.CreateEncryptor(), CryptoStreamMode.Write);
                csRijndael.Write(totalInfo, 0, (int)totalInfo.Length);
                csRijndael.FlushFinalBlock();
                string base64enc = System.Text.Encoding.ASCII.GetString
                    (ms.GetBuffer(), 0, (int)ms.Length);
                xnFormName.SetValue(base64enc);

    hope this solves your problem

    Qazi Anis
    Technical Architect
    Bitwise Inc
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.