Store InfoPath file Attachments to Smart Object


Badge +6

HI,


I would like to store the InfoPath file Attachments to Smart Object. I created the smart Object with following Fields ID,FileName, HyperLink (Link to sharePoint document Library Where it store the actual document) So my question is how can i fetch the file name from the InfoPath file attachment control without writing the code behind?


Note: I tried with code behind, but when i open a form it is opening in InfoPath 2007 Client instead of opening in Web browser. I guess code behind has lot of issues to deploy.


 


16 replies

Badge +4

I don't have an answer on the filename, but it is possible to open Infopath forms with code behind in a browser, but it does require a Sharepoint administrator to approve the form. Are you integrating with the form in a K2 process and then deploying the K2 process?

Badge +6

Thanks for your reply. Yes I am integrating the InfoPath form in K2. I also tried the InfoPath Form Code behind, but when i deploy using K2, Form is opening in InfoPath Client instead of Web browser. Last time i also tried with Deploying the form with Sharepoint Central administration it didnt work. Right now i havent remember what was the error i got at that time. Any way i will try one more time then i will update you the issues which i got.


If i write a code behined in infoPath form, Is it possible to use K2 Classes to update the smart objects fields like fileName and File Content? If yes can you tell me what namespaces i have to Reference and sample code or steps if possible.

Badge +4

1.       Deploy the process, which will updated InfoPath Form.


2.       Go to the site where the form library resides


a.       Click “Site Actions -> View All Site Content”


b.      Click on “K2 Blackpearl InfoPath Templates”


                                                               i.      The new template should be listed here.


                                                             ii.      Right click on it and select “Copy Shortcut”.


4.       Now in MOSS Central Administration.


a.       On the menu click “Application Management”


b.      Under “InfoPath Form Services”


                                                               i.      Click “Manage form templates”


                                                             ii.      Click “Upload form template”


                                                            iii.      Click “Browse” and paste the shortcut copied.


                                                           iv.      Click “Open”


                                                             v.      Click “Upload”


c.       Activate the new form to the site collection where the Form Library resides.


5.       Back on the form library


a.       In “Settings -> Form Library Settings”


b.      Under Content Types click “add from existing site templates”. You need to activate content types under the "Advanced Settings" to see this section.


c.       Select the new content type. It may be appended with a sequential number e.g. “PurchaseRequest6".


d.      The form should now be able to open in InfoPath Form Services. If not, then there is something else wrong with the form that Infopath Forms Services does not like.

Badge +6
Ok I will give a try. What about namespaces i can use in InfoPath Form so that i can update the SmartObjects though code behind.
Badge +10

Hi VijayKumar


I am not sure if this would apply to your situation but I was able to get the filename after uploading the document to sharepoint without using code.  


I noticed that the filename isn't required when uploading to a SharePoint Document Library SmartObject Create method.  However, the filename does appear in the document library after uploading even without specifying it (It appears that the SharePoint APIs are extracting the filename from the content header of the binary file when its uploaded). 


In addition one of the return values of the SmartObject returns the filename which might be useful if you need the filename later on in the InfoPath form or within the workflow.


Steps to reproduce.


1.  Created the SmartObject for the document library using the Smart Objects Services Tester tool.


2.  Integrated the SmartObject into the infoPath form selecting the Create method.


3.  Added a fileattachment field to the infopath form and a button and configured the button's rules to call the Create method of the Smartobject I integrated passing only the fileattachment field as the value for the required content field.  I configured the return property FileLeafRef to populate the fileName field the file was uploaded to sharepoint.


 


I hope this helps.


Tim


 

Badge +8

I wanted to add one thing to this post because I ran into a small challenge.


I wanted to be able to use the GetList method of the smartobject to show a list of documents that I had uploaded with links to the documents.  The challenge I had was that the SharePoint ServiceObject does not give you a straight link but an xml formatted structure….<hyperlink><link>http://www.thelink.com</Link>...etc


To get around this I used some of the built in string methods to parse down the structure and leave the link.  For the hyperlink properties add the following in the display and link to data sources:


substring-before(substring-after(LinkToItem_K2_ServiceDefined, "<hyperlink><link>"), "</link>")


-Eric

Badge +8

Here is a link to a little video I did to show it in action:


http://www.k2underground.com/files/folders/videos/entry28307.aspx

Badge +6
Thank you very much for the video. It really solves my problem.
Badge +8

Excellent...Glad I could help


-Eric

Badge +6

Eric,


Can i have the Sample InfoPath Form or project which you showed in the Video? I want to checke the Actions in the Upload button. 


 

Badge +8

I have attached the infopath form that I used in the video to this post. 


 A couple of notes about the stuff behind the upload button.  I created a doclink field and a docname field in order to store the return values from the upload which works good if you only want to upload 1 document in a more realistic scenario you might want to have a smartbox smartobject to store the URLs, file names, and some uniqueID for all the documents related to this instance of the form and then keep the uniqueID in the form somewhere so you can get the list of documents back at a later stage of the process.  In my simple case I just added the getlist method of the SharePoint smartobject so that I could retrieve links to all the documents that I uploaded however it will include all documents in that library rather than just the ones related to this instance of the form. 


 I hope this helps.


-Eric

Badge +4
Another option to retrieve the list of documents for the particular process is to create a hidden column on the doc. lib. which will carry the ProcessInstanceID which can be stored in the Infopath XML. This way when performing the get list you could supply the ProcessInstanceID to only return the documents for a particular instance. This however would only work for attachments added at task events during the process and not work for attachments during the initial form view, because at this point the process has not been started and therefore you would not have a ProcessIntanceID.
Badge +6

 


I tried your video tutorial and its great. When i follow your video tutorial, I can able to upload the documents to root site, But i want to upload the documents to document library in a subsite and Every time i upload the document i have to create a Folder and then upload documents into it.


How can i do this?


Thanks

Badge +8

The location of where the documents get uploaded is based upon the smartobject that is being used.  You can either create a smartobject for that particular library on the subsite and use that smartobject in the form or you can use the dynamic smartobject capability where you pass URL to a document libary in the input parameters of the Create method.  There is more info on this new dynamic capability here:  http://k2underground.com/blogs/fromthebench/archive/2008/11/21/leverage-existing-smartobjects-to-access-new-sharepoint-sites-created-with-templates-or-site-definitions.aspx


 I hope that helps.


-Eric

Badge +6

Now i am able to save documents into Document library. I created the Document Number as column in the document library so that i can filter attachments based on the document number. In my requirement different document number may contain same attachment name (File Name). I know SharePoint wont allow to store same name. For that i want to change the file name in the upload button ( using Rules) in InfoPath. but it seems not working.


How can i change the attachment file Name using K2 Smart object in InfoPath Form.


Please advice me how to advise me how to do this.


Thanks 


 

Badge +2

Hi Vijay


 


I don't know if you are still having trouble with this, but Johnny recently wrote a very informative blog with a .pdf file outlining in detail how to upload documents to SharePoint through InfoPath using a smartObject:


http://www.k2underground.com/blogs/johnny/archive/2009/11/03/the-proper-way-to-attach-files-in-k2-infopath-processes.aspx


 


This helped me alot to better understand how you can use a smartObject to do document uploading.


HTH

Reply