How to get the attached file out from task form - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

How to get the attached file out from task form

Last post 12-09-2011 10:59 AM by Hilary Stoupa. 17 replies.
Page 1 of 2 (18 items) 1 2 Next >
Sort Posts: Previous Next
  • 08-14-2008 06:05 AM

    • s42bm
    • Top 500 Contributor
    • Joined on 04-21-2008
    • Posts 32

    How to get the attached file out from task form

     Hi everyone.

    I have an InfoPath task form with a file attachment control associated to a SharePoint workflow. The file was uploaded successfully and I got an encoded string for attached file. I wonder if the file was saved in somewhere on my SharePoint site automatically or I have to get it back by coding? If I need to write some code, could you please guide me to some place where I can find more info. Thanks!

     

  • 08-17-2008 07:52 AM In reply to

    Re: How to get the attached file out from task form

    Attachments are encoded in the file itself and do not go into Sharepoint on there own.

    I would either use code to browse for the file and place it in Sharepoint with a hyperlink in InfoPath or attach it and extract it to Sharepoint.

  • 08-18-2008 04:45 AM In reply to

    • s42bm
    • Top 500 Contributor
    • Joined on 04-21-2008
    • Posts 32

    Re: How to get the attached file out from task form

     Thank you, Clay. I'll try both ways you pointed out.

  • 08-19-2008 04:37 AM In reply to

    Re: How to get the attached file out from task form

    Hi --

    There is also a sample here that may help you. This sample form copies the attachment to a SharePoint document library and creates a link in your form to the attachment. Give it a try -- let me know if you need help with it!

    Hilary Stoupa

  • 08-20-2008 06:19 AM In reply to

    • s42bm
    • Top 500 Contributor
    • Joined on 04-21-2008
    • Posts 32

    Re: How to get the attached file out from task form

     Hi Hilary,

    I read the sample code you showed me, it's very helpful. I have a workflow that has an InfoPath form as its task form. May I extract the attachment within this task form in the workflow instead of handling by the code on form submission and practically which approach is better? Thank you!

  • 08-20-2008 07:21 AM In reply to

    Re: How to get the attached file out from task form

    I'm afraid I have had very little experience with workflow, so you'd need to try it to find out.... I would assume you could use the code in the changed event of the field that the file is being attached to, so that when a file is attached to the form it is immediately saved to another site and replaced with a link. If you use the task pane for this activity, the user will be able to continue working in the form without any delays. I think either approach is valid, but if you find that one is better than the other, do post and let us know, that would be helpful information for the community.

    Hilary Stoupa

  • 08-25-2008 08:28 AM In reply to

    • feesh
    • Not Ranked
    • Joined on 09-25-2007
    • Posts 11

    Re: How to get the attached file out from task form

    Hi Hilary

    I think the example you posted is what I am looking for to help solve a problem I am having however the only issue is that I can't open the example because it was created in a newer version of Visual Studio then the one I have (which is 2003). Is there another example for VS 2003 or is there an easy way to explain what is going on?

    My problem is really two fold. First I am having an issue with file sizes getting to big and it causing delays to save/open the form. In this case creating a link to open a file that is actually stored either on a network drive or sharepoint site should help this I imagine. The other issue is documented in my post here: http://www.infopathdev.com/forums/t/8896.aspx. If you can provide any help it would be greatly appreciated.

    Chris

     

  • 08-25-2008 10:06 AM In reply to

    Re: How to get the attached file out from task form

    Hi, Chris:

    As far as why the name turns to gibberish when the attachment is opened from InfoPath and what to do about it -- I don't know that one. However, if you write the file off someplace and exchange it with a link, that problem may go away.

    Here is what I would suggest. In the OnAfterChange event of your file attachment control, you should be able to add some code that uses the sample provided in that link in the "Create a Decoder Class" section to write to a network share.

    In the sample, if you unzip it and look at some of the files with notepad, you should be able to get an idea of what is going on even though you can't run it in Visual Studio. FormCode.cs has methods to get the attachement name and decode it, and the task pane in the form (tpRouting.htm) actually sends the file off to SharePoint.

    As far as the type of control to place your new file link in -- if it is on a network share, you may experience a little pain -- I found this post at this site that discusses it a bit.

    I'd start simply -- figure out how to decode and write out your file, then start working on how to get the user back to that file from your form....Let me know if you need more concrete help, I realize this is pretty conceptual.

    Hilary Stoupa

  • 08-25-2008 11:47 AM In reply to

    • feesh
    • Not Ranked
    • Joined on 09-25-2007
    • Posts 11

    Re: How to get the attached file out from task form

    Hi Hilary

    Thanks for the reply. I think your pointing me in the right direction and while I haven't gotten my hands dirty yet, I should be able to atleast decode the name and use it to open a file.

    That being said, I am still unclear how to apply all this. How does this code run in the form? Do you put the default attachment control on the form and call the code you wrote in VS in an on change event?? Or does this create a custom control? I am still uncertain how this works.

    Chris

  • 08-25-2008 12:12 PM In reply to

    Re: How to get the attached file out from task form

    Sorry, Chris! I should have been more precise. No custom control needed, just add the normal InfoPath file attachment control. After you read the contents off, decode into a new file and save someplace, you can set the text value back to blank so that you aren't storing that bulky file. You could even use some conditional formatting to decide when to show/hide the file control, and add another field (again, see my earlier link for the conversation on linking to a file in InfoPath, you may have to manipulate things a bit) that you will use to store the link to the file.

    That way, the user adds the file using the normal IP experience, and, like magic, the file gets stored off someplace else and they are left with a link.

    Oh, and in your onAfterChange, for you decode stuff, do it in an if statement that checks to make sure the event is an 'Insert' event, like this:

    if ( !e.Operation.Equals("Insert"))

    That way your event won't run twice... although, you'll probably want to do something on Delete, too, so that if your user choses to get rid of the file they selected, it isn't hanging out where you wrote it off to, cluttering up the place....

    Hilary Stoupa

  • 08-25-2008 12:30 PM In reply to

    • feesh
    • Not Ranked
    • Joined on 09-25-2007
    • Posts 11

    Re: How to get the attached file out from task form

    No need to apologies. You have been very helpful.

     

    Just to clarify - all I need to do is put the modified code from your example in the onAfterChange event? No extra files are needed to somehow be included in the form?

     

  • 08-25-2008 12:42 PM In reply to

    Re: How to get the attached file out from task form

    Are you comfortable with C#? You won't need everything in that sample in the FormCode.cs.

    I'd create an onAfterChange event on the attachement control and add two of the methods to your form code -- DecodeAttachment and GetAttachmentName. You can pass DecodeAttachment the text value of your file attachment node to get back a byte array, and you can pass the entire node to GetAttachmentName to get back the file name you'll need when you go to save the file off.

    The Microsoft link I pointed you to earlier has a method called SaveAttachment that you should be able to use to write it all off to the file system.

    Let me know if you get stuck, okay?

    Hilary Stoupa

  • 09-22-2008 02:42 AM In reply to

    • jeeva
    • Top 150 Contributor
      Male
    • Joined on 07-18-2008
    • Bangalore
    • Posts 79

    Re: How to get the attached file out from task form

     Hi

    I am new to this Infopath Forms.I have a same problem.

    My scenario is i have  attached file in my form, but i am not able to publish this attached file to sharepoint library.

    how can i get my attached file link.

    could u tell me in step by step procedure of this solution.

     

     

  • 09-22-2008 02:57 AM In reply to

    • jeeva
    • Top 150 Contributor
      Male
    • Joined on 07-18-2008
    • Bangalore
    • Posts 79

    Re: How to get the attached file out from task form

     Hi Hilary,

     How  can i solve this problem using Workflow tasks.

    Could you please explain step by step procedures to this issue.

  • 09-23-2008 11:14 AM In reply to

    • s42bm
    • Top 500 Contributor
    • Joined on 04-21-2008
    • Posts 32

    Re: How to get the attached file out from task form

    Because I don't know what exactly you need, I just provide you a possible solution based on my assumption.

    In a workflow, we create a task and link it to a task form consisting of an attachment type field. When the form being sent back, we have attached document as a string. In OnTaskChanged activity, we can get the document and put it somewhere on your sharepoint site.

    Using OnTaskChange_AfterProperties.ExtendedProperties["field_name"] to get the attachment as a string. Pass this string to a function to put it back in a file. The following link showed how to dig the content out from the string. Good luck!

    http://blogs.msdn.com/pranab/archive/2007/07/02/how-to-add-the-attachment-from-an-infopath-2007-form-to-a-document-library.aspx

     

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