How to upload a file to a file system in InfoPath form?

  • 14 October 2006
  • 1 reply
  • 13 views

Badge +4
In InfoPath form, there is an attachment control for uploading file attachment. But it is recommended by an article in this forum that the file size should not be more than 4MB. For the K2 projects I am working on, if users upload files(10MB), it will cause problems and K2 might run out of memory.

So we need to change the upload feature to upload the files to a file system and only save the link to the uploaded file in the InfoPath form.

InfoPath form does not have a file explorer control. How can I implement this?

I can add a hyperlink, when click it, it will open an aspx page to upload files. But I don't know how to pass the uploaded file locations back to the InfoPath form to save them.

Thanks for your help
coenw

1 reply

Badge +7
Hi coenw,

you can have the whole functionality within InfoPath.
Below a short code example of how to achieve what you want to do:



IXMLDOMNode hyperlink = thisXDocument.Dom.SelectSingleNode(xpath of textbox control, used as the datasource for the hyperlink);

//you should have a kind of ID for each new request so that the subfolders you create are always unique and there is no possibility to overwrite an existing one
IXMLDOMNode ID = thisXDocument.Dom.SelectSingleNode(xpath to ID);

//top folder under which you can create new subfolders for each request, keep in mind that the users will need read and write permission to this folder !
string strDirectory = @"absolute pathHere_I_Put_My_Attachments_Folder";

//create a new folder
System.IO.DirectoryInfo dir = System.IO.Directory.CreateDirectory(strDirectory + ID.text);

//write the full path of the new folder into the textbox control you want to use as the datasource for your hperlink
hyperlink.text = dir.FullName;

You can use this code in a button event for example. When everything works create a Hyperlink and use the textbox as the source for the link. Like this the link points to the folder you just created. When people click the link the folder opens and they can just drag and drop all required files into the folder. You can have the link in all views of your process so that the files are available during the entire instance.

Hope this helps

Reply