|
Source: wss.made4the.net - by Jeremy Thake
I used STSDev to create this Solution in Visual Studio to give me the Build Targets quick options for deploying in my development environment. The benefits to this approach is:
The sample code can be found on my Sky Drive Sample Code Walk Thru
The solution consists of 2 main elements: InfoPath FormInfoPathDeploymentSameple FeatureThis feature essentially includes the .xsn file and also a trigger to deploy the Form to Central Administration using these added lines of code in the feature.xml. This is discussed in Sahil Malik's Added to <Feature> element as attributes ReceiverClass="Microsoft.Office.InfoPath.Server.Administration.XsnFeatureReceiver" ReceiverAssembly="Microsoft.Office.InfoPath.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" and Added as a child element of <Feature> element <Properties> <Property Key="FeatureName" Value="JeremyThake InfoPath Form Template Sample Feature"/> </Properties> InfoPathDependency FeatureThis feature includes the two SharePoint Lists used
There are two main UDCX stub files attached to this feature. MainSubmit.udcx <?xml version="1.0" encoding="UTF-8"?> <?MicrosoftWindowsSharePointServices ContentTypeID="0x010100B4CBD48E029A4ad8B62CB0E41868F2B0"?> <udc:DataSource MajorVersion="2" MinorVersion="0" xmlns:udc="http://schemas.microsoft.com/office/infopath/2006/udc"> <udc:Name>Main submit</udc:Name> <udc:Description>Format: UDC V2; Connection Type: SharePointLibrary; Purpose: WriteOnly; Generated by Microsoft Office InfoPath 2007</udc:Description> <udc:Type MajorVersion="2" MinorVersion="0" Type="SharePointLibrary"> <udc:SubType MajorVersion="0" MinorVersion="0" Type=""/> </udc:Type> <udc:ConnectionInfo Purpose="WriteOnly" AltDataSource=""> <udc:WsdlUrl/> <udc:SelectCommand> <udc:ListId/> <udc:WebUrl/> <udc:ConnectionString/> <udc:ServiceUrl UseFormsServiceProxy="false"/> <udc:SoapAction/> <udc:Query/> </udc:SelectCommand> <udc:UpdateCommand> <udc:ServiceUrl UseFormsServiceProxy="false"/> <udc:SoapAction/> <udc:Submit/> <udc:FileName>Specify a filename or formula</udc:FileName> <udc:FolderName AllowOverwrite="1" /> </udc:UpdateCommand> <!--udc:Authentication><udc:SSO AppId='' CredentialType='' /></udc:Authentication--> </udc:ConnectionInfo> </udc:DataSource> SharePointConnectionTemplate.udcx <?xml version="1.0" encoding="UTF-8"?> <?MicrosoftWindowsSharePointServices ContentTypeID="0x010100B4CBD48E029A4ad8B62CB0E41868F2B0"?> <udc:DataSource MajorVersion="2" MinorVersion="0" xmlns:udc="http://schemas.microsoft.com/office/infopath/2006/udc"> <udc:Name>Projects</udc:Name> <udc:Description/> <udc:Type MajorVersion="2" MinorVersion="0" Type="SharePointList"> <udc:SubType MajorVersion="0" MinorVersion="0" Type=""/> </udc:Type> <udc:ConnectionInfo Purpose="ReadOnly" AltDataSource=""> <udc:WsdlUrl/> <udc:SelectCommand> <udc:ListId/> <udc:WebUrl/> <udc:ConnectionString/> <udc:ServiceUrl UseFormsServiceProxy="false"/> <udc:SoapAction/> <udc:Query/> </udc:SelectCommand> <udc:UpdateCommand> <udc:ServiceUrl UseFormsServiceProxy="false"/> <udc:SoapAction/> <udc:Submit/> <udc:FileName>Specify a filename or formula</udc:FileName> <udc:FolderName AllowOverwrite=""/> </udc:UpdateCommand> </udc:ConnectionInfo> </udc:DataSource> These two files are used by the FeatureReceiver as templates when creating instances of the UDCX files in the DataConnectionLibrary List. CreateDataConnectionLibraryListItem(web, "Projects", properties.Definition.RootDirectory, "DataConnectionLibrary"); CreateDataConnectionLibraryMainSubmitListItem(web, properties.Definition.RootDirectory, "DataConnectionLibrary"); The methods are below: /// <summary> /// Creates a udcx file based on the template for SharePoint List connections autogenerated by InfoPath 2007 /// </summary> /// <param name="web"></param> /// <param name="listName"></param> /// <param name="rootDirectory"></param> /// <param name="dataConnectionLibraryListName"></param> private void CreateDataConnectionLibraryListItem(SPWeb web, string listName, string rootDirectory, string dataConnectionLibraryListName) { //load template.udcx file string templateFileName = rootDirectory + "\\sharepointConnectionTemplate.udcx"; XmlDocument doc = new XmlDocument(); doc.Load(templateFileName); XmlNamespaceManager nameSpaceManager = new XmlNamespaceManager(doc.NameTable); nameSpaceManager.AddNamespace("udc", "http://schemas.microsoft.com/office/infopath/2006/udc"); //replace token with ListID Guid listID = web.Lists[listName].ID; XmlElement root = doc.DocumentElement; XmlNode listIdNode = root.SelectSingleNode("//udc:DataSource//udc:ConnectionInfo//udc:SelectCommand//udc:ListId", nameSpaceManager); listIdNode.InnerText = "{" + listID.ToString() + "}"; XmlNode webUrlNode = root.SelectSingleNode("//udc:DataSource//udc:ConnectionInfo//udc:SelectCommand//udc:WebUrl", nameSpaceManager); webUrlNode.InnerText = web.Url.ToString(); XmlNode descriptionNode = root.SelectSingleNode("//udc:DataSource//udc:Description", nameSpaceManager); descriptionNode.InnerText = "Format: UDC V2; Connection Type: SharePointList; Purpose: ReadOnly;"; UploadToFileToLibrary(web.Lists[dataConnectionLibraryListName], doc, listName + ".udcx"); } /// <summary> /// Creates the UserProfileService udcx connection string based on environment /// </summary> /// <param name="web"></param> /// <param name="rootDirectory"></param> /// <param name="dataConnectionLibraryListName"></param> private void CreateDataConnectionLibraryUserProfileConnectionListItem(SPWeb web, string rootDirectory, string dataConnectionLibraryListName) { XmlDocument doc = new XmlDocument(); string connectionFileName = "GetUserProfileByName.udcx"; doc.Load(rootDirectory + "\\" + connectionFileName); XmlNamespaceManager nameSpaceManager = new XmlNamespaceManager(doc.NameTable); nameSpaceManager.AddNamespace("udc", "http://schemas.microsoft.com/office/infopath/2006/udc"); XmlElement root = doc.DocumentElement; XmlNode wsdlUrl = root.SelectSingleNode("//udc:DataSource//udc:ConnectionInfo/udc:WsdlUrl", nameSpaceManager); wsdlUrl.InnerText = web.Url.ToString() + "/_vti_bin/UserProfileService.asmx?WSDL"; XmlNode serviceUrl = root.SelectSingleNode("//udc:DataSource//udc:ConnectionInfo//udc:SelectCommand//udc:ServiceUrl", nameSpaceManager); serviceUrl.InnerText = web.Url.ToString() + "/_vti_bin/UserProfileService.asmx"; UploadToFileToLibrary(web.Lists[dataConnectionLibraryListName], doc, connectionFileName); } private void CreateDataConnectionLibraryMainSubmitListItem(SPWeb web, string rootDirectory, string dataConnectionLibraryListName) { XmlDocument doc = new XmlDocument(); string connectionFileName = "MainSubmit.udcx"; doc.Load(rootDirectory + "\\" + connectionFileName); XmlNamespaceManager nameSpaceManager = new XmlNamespaceManager(doc.NameTable); nameSpaceManager.AddNamespace("udc", "http://schemas.microsoft.com/office/infopath/2006/udc"); XmlElement root = doc.DocumentElement; XmlNode folderName = root.SelectSingleNode("//udc:DataSource//udc:ConnectionInfo//udc:UpdateCommand//udc:FolderName", nameSpaceManager); folderName.InnerText = web.Url.ToString() + "/Lists/TestFormLibrary/"; UploadToFileToLibrary(web.Lists[dataConnectionLibraryListName], doc, connectionFileName); } private void UploadToFileToLibrary(SPList dataConnectionLibrary, XmlDocument doc, string connectionFileName) { // Convert Xml Document To Byte Array.byte[] StringWriter sw = new StringWriter(); XmlTextWriter xw = new XmlTextWriter(sw); doc.WriteTo(xw); System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); byte[] docAsBytes = encoding.GetBytes(sw.ToString()); //create new list item and upload .udcx file in data connection library SPFolder dataConnectionLibraryFolder = dataConnectionLibrary.RootFolder; SPFile dataConnectionLibraryFile = dataConnectionLibraryFolder.Files.Add(connectionFileName, docAsBytes); //approve SPFile dataConnectionLibraryFile.Approve("Approved when feature activated."); }
|
Developing a InfoPath Solution using a Solution Package

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Hosted generously by CustomWare










Comments (12)
Jun 29, 2009
Kirk Hofer says:
Hmmm...did you try this? The Site Columns referenced with the GUIDs do not matc...Hmmm...did you try this? The Site Columns referenced with the GUIDs do not match those in the schema.xml. So when deployed, this probably didn't work, or does it work regardless the GUID? Haven't tried it yet myself but thought I would post this. I have been doing too much inside the manifest.xsf
Jul 24, 2009
Ulrich Strauss says:
I did this in a similar way. However there is a small issue with updates. If you...I did this in a similar way. However there is a small issue with updates. If you upgrade the solution, the upgradesolution will copy the updated infopathform to the feature-directory, however it will not deploy and activate it. Anybody found a way to upgrade those forms?
Aug 19, 2009
Anonymous says:
Does this only work for web enabled InfoPath forms or can it also be used for cl...Does this only work for web enabled InfoPath forms or can it also be used for client application only forms?
Dec 11, 2009
Alex Clark says:
Thanks for posting this Jeremy this was very useful in developing a similar solu...Thanks for posting this Jeremy this was very useful in developing a similar solution. The important thing here to remember is that the url is relative to the server root so essentially even if you move servers it will still work (as long as the same data connection library exists in the same location of course).
In reply to the above - yes this should work fine for client application forms too. In fact when you deploy the InfoPath form as part of a feature to a SharePoint site it will open in the client application by default unless you change the settings.
Dec 22, 2009
Chad La Fournie says:
Hi Jeremy, I have been trying to replicate your process as per the above as wel...Hi Jeremy,
I have been trying to replicate your process as per the above as well as the web casts. However, I have run into an issue that I suspect does relate to guids as per the comment above. Assuming that this did work could you provide the code? Note that I did download the code posted on your skydrive but it appears somewhat out of date. The error I am getting (both in my implementation and in deploying the wsp from your sample code) is that the udcx file is "not from a data connection library."
Thanks in advance for any help you can offer.
Chad La Fournie
Dec 23, 2009
Jeremy Thake says:
I would recommend creating a Data Connection Library and then using SPSource to ...I would recommend creating a Data Connection Library and then using SPSource to reverse engineer into a list_elements.xml file to provision this. In the web casts I go through this.
Dec 23, 2009
Chad La Fournie says:
Thanks for the reply. That was actually the method I was following. I did end u...Thanks for the reply. That was actually the method I was following.
I did end up resolving the issue. The lists_manifest.xml file generated by spsource had arbitrary values (10000) for the template type. After manually changing the types to 130 in both the ListTemplate and the ListInstance the error message no longer appears and things appear to be working correctly.
Mar 01
Kostadin Markov says:
Hi, good article! My question is - must I use Visual Studio 2010, or I can ...Hi, good article!
My question is - must I use Visual Studio 2010, or I can stay with 2008 to reimplement the funcionality from the webcasts?!
Mar 01
Jeremy Thake says:
This tutorial is for VS2008. In general, the majority of tutorials you will find...This tutorial is for VS2008. In general, the majority of tutorials you will find on SharePoint 2007 will be on VS2008. VS2010 will be for any SharePoint 2010 relevant stuff.
Mar 01
Kostadin Markov says:
Ok, I made a shot, but I rechecked and there is VS2010 in the last tur...Ok, I made a shot, but I rechecked and there is VS2010 in the last turorial - http://www.screencast.com/t/NTE2NzFj
. I will watch thoroughly all the four to make things clear!
Mar 01
Jeremy Thake says:
Yes apologies, things are slightly different in the UI between VS2008 and VS2010...Yes apologies, things are slightly different in the UI between VS2008 and VS2010. But the code etc shown above will work in VS2008 also.
Mar 03
Forms Builder says:
Good information here. Really helped me out!Good information here. Really helped me out!