Reading InfoPath XML from a SharePoint Forms Library

T

TimPGade

DL,

Does anybody have a better approach to reading InfoPath XML from a
SharePoint Forms Library?

Here is what I have:
1) Create a DEV virtual server that uses a different port than the Default
SharePoint port
2) Create a custom Web Service on DEV port
3) Create a WSDL for the Web Service and make mods as outlined in SDK
4) Copy the files to the ISAPI folder
5) Add a Web Service reference to the custom Web Service in the calling
application
6) Call the Web Service reference using one of these methods (from source 3)
Rename
Delete
GetLatestVersion
Search
CheckOut
UndoCheckout
UploadDocument
CheckIn
GetCheckOutStatus
8) Call the GetLatestVersion and retrieve the form as a byte stream
9) Load the byte stream into an XML document


Here is the basis for my findings:

(1) WSS SDK search on "Creating a Web Service for Remote Check-In and
Check-Out"

(2) Writing Custom Web Services for SharePoint Products and Technologie
<http://msdn.microsoft.com/library/d.../html/ODC_WritingCustomWebServicesforSPPT.asp>

(3) Windows Sharepoint Services Web Service Example
<http://blogs.msdn.com/brad_mccabe/archive/2005/03/01.aspx>
 
P

Patrick Halstead [InfoPath MVP]

Hi Tim,

Have you looked at chapter 9 in "Developing Solutions with Microsoft
InfoPath" (by MS Press)? This covers SharePoint. There is a section at the
end on using SharePoint list adapter to get the form name. You can just
create a data connection to the form library from your solution. Then, you
can use HTTP DAV directly to get the file info. Let me know if you need a
code snippet, and I'll dig one up and post it to our website HowTo.

Regards,
Patrick
http://www.infopathdev.com/
 
T

TimPGade

Thanks Patrick,

A code snippet would be most helpful. I have the book and I considered using
WebDAV first but could not find any good WebDAV references to get me going in
the right direction.

Thanks
Tim
 
P

Patrick Halstead [InfoPath MVP]

Hi Tim,
I've cobbled together some code snippets and haven't had time to test them,
but this should give you some idea. Good luck!
Patrick
http://www.infopathdev.com/

public void SharePointListAdapterDropDown_OnAfterChange(DataDOMEvent e)
{

// filter out noise
if (e.IsUndoRedo || "Insert" != e.Operation || "" == e.NewValue)
return;

// prevent infinite loops when loading files from ShP
if(true == fGettingSharePointFile)
{
fGettingSharePointFile = false;
return;
}
fGettingSharePointFile = true;

// get the selection
string sKey = e.Site.text;

// "test" is the name of your sharePoint list adapter data connection
SharepointListAdapter oSpla =
(SharepointListAdapter)thisXDocument.DataAdapters["test"];
sUrl = oSpla.SiteUrl;

// "test" is also the name of a secondary data source that you will
pre-populate
IXMLDOMDocument2 oDom = (IXMLDOMDocument2)thisXDocument.GetDOM("test");
oDom.setProperty("SelectionNamespaces",
"xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolut
ion\"");
// filter on the value using sKey
string sName =
oDom.selectSingleNode(string.Format("//dfs:test[@key1=\"{0}\"]/@Value",
sKey)).text;

// Note: you need to set sSP_FOLDER to your SharePoint folder
// - you can do this programmatically using SolutionURL and walking up the
string sFilename = sUrl + sSP_FOLDER + sName;

// random schema - please change to suit your insertion needs
IXMLDOMNode oParentNode = getNode("//my:root/my:section1");
IXMLDOMNode oNode = getNode("//my:root/my:section1/rd:section2");

// Load the XML DOM from the file
IXMLDOMDocument2 oXml = (IXMLDOMDocument2)thisXDocument.CreateDOM();
oXml.async = false;
oXml.load(sFilename);
oXml.setProperty("SelectionNamespaces",
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:rd=\"http://www.infopathdev.com/Samples/ShP/GetFile\"
xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"
xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-07-1
7T17:30:19\"
xmlns:xd=\"http://schemas.microsoft.com/office/infopath/2003\"");

// Note: be careful calling replaceChild since it can be slow
IXMLDOMNode oNewNode = oXml.selectSingleNode("//my:root/my:section1//" +
oExistingNode.nodeName);
oParentNode.replaceChild(oNewNode.cloneNode(true), oExistingNode);

return true;
}
 
T

TimPGade

Thanks for the code Patrick,

I see the snippet is using IP and the built-in SharePointListAdapter. This
is great for IP however since I am using a VB.NET app it it appears I have to
reference the SP .NET libraries which I cannot do unless I the app runs on
the server (hence a web service). I was hoping to find a WebDAV example that
showed how to accomplish this simply using .NET. If you haved any pointers on
how I might pursue this please let me know.

Tim
 
P

Patrick Halstead [InfoPath MVP]

Hi Tim,
It's late, and I am utterly confused. What does IP mean? You mean the
InfoPath object model? Well, the code is C#? You are running InfoPath,
right? What's wrong with the IP OM? I'm probably just confused, but that's
..NET as far as I know. There are probably half a dozen ways to do this. What
are your client requirements?
Sorry,
Patrick Halstead
http://www.autonomysystems.com/
 
T

TimPGade

Hi Patrick,

Sorry for the confusion, yes I am referring to the InfoPath object model by
IP. My customer has a SharePoint form library that contains an InfoPath form.
The customer wants to be able to retrieve the XML file(s) from the form
library outside of InfoPath to extract and repurpose the data in downstream
operations.

If we use the SharePoint object model, we can use the GetFile service.
However, to use the SharePoint object model the application needs to run on
the server to reference the SharePoint assemblies. So to get the file to the
client we have to create a "broker" web service on the SharePoint server to
get the file and return in to the external client by creating a web reference
on the client and calling the broker service.

I was hoping that we could use WebDAV to call SharePoint via HTTP and have
SharePoint return the contents of the file and eliminate the broker
altogether. I understand your code it's just that the customer is not using
InfoPath at this juncture of the process.






--
Get what you expect from technology!


Patrick Halstead said:
Hi Tim,
It's late, and I am utterly confused. What does IP mean? You mean the
InfoPath object model? Well, the code is C#? You are running InfoPath,
right? What's wrong with the IP OM? I'm probably just confused, but that's
..NET as far as I know. There are probably half a dozen ways to do this. What
are your client requirements?
Sorry,
Patrick Halstead
http://www.autonomysystems.com/
 
P

Patrick Halstead [InfoPath MVP]

Hi Tim,
Sorry for delay. I'm pretty sure you can use WebDAV. Another approach would
be RPC. Have you looked at the SharePoint SDK? Sorry I don't have more time
now.
Cheers,
Patrick
http://www.infopathdev.com/


TimPGade said:
Hi Patrick,

Sorry for the confusion, yes I am referring to the InfoPath object model by
IP. My customer has a SharePoint form library that contains an InfoPath form.
The customer wants to be able to retrieve the XML file(s) from the form
library outside of InfoPath to extract and repurpose the data in downstream
operations.

If we use the SharePoint object model, we can use the GetFile service.
However, to use the SharePoint object model the application needs to run on
the server to reference the SharePoint assemblies. So to get the file to the
client we have to create a "broker" web service on the SharePoint server to
get the file and return in to the external client by creating a web reference
on the client and calling the broker service.

I was hoping that we could use WebDAV to call SharePoint via HTTP and have
SharePoint return the contents of the file and eliminate the broker
altogether. I understand your code it's just that the customer is not using
InfoPath at this juncture of the process.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top