Embedded Resource Files

O

online.identity.9

How can I access a Resource File via javascript in InfoPath 2003? I
have a form in which I've attached a couple of additional documents,
these documents are of various types (Powerpoint, Word, etc). I'd
like to be able to extract these documents from the form in javascript
and write them to the users temp directory, but I can't seem to find a
way of accessing the embedded files. Any ideas?
 
O

online.identity.9

I have routines to encode and decode Base64 in javascript (though
javascript is SLOW, it takes 30 seconds to decode a 100K file). My
issue is getting at Resource Files, not files imported by the user.
 
S

S.Y.M. Wong-A-Ton

Sorry, I misunderstood your question. Could you please post the javascript
code to encode/decode? Other people in the group might benefit from it...

Now onto your issue: Resource files are used in InfoPath to be able to
internally link to an HTML or XML file that you would typically use in a
custom task pane or through a data source. As far as I know, there are no API
methods to retrieve those resource files. But here's an idea you can try out:
Create an InfoPath form template that has an attachment control on it. Then
fill out forms and attach the documents you want to embed. Note: You could
use a repeating table containing an attachment control to embed all of the
documents in one form. Once you've done this, add the filled out form as a
resource file to your other InfoPath form template that uses resource files
and then create an XML document receive data connection that uses the
resource file you added. Then in code, you can use something like
XDocument.DataObjects["<your_datasource_name>"].DOM.selectSingleNode("//my:attachmentfield").text
to get the base64 encoded string of the attached document. Then you can use
your javascript code on this to convert it to a binary file and save it
locally.

I have not tried out what I've outlined above, so if you get stuck, let me
know. It's a cool scenario, BTW.
 
O

online.identity.9

I thought about that, it's just a little too convoluted for my tastes,
although I've done much much worse things to Infopath. I think I'm
just going to have to post the documents in a publicly accessible
place and pull them down when needed.

Regarding the base64 stuff. Here's a link to some javascript that
does encoding and decoding, http://www.webtoolkit.info/javascript-base64.html

A few things to worry about though, files embedded via the File
Attachment control contain more then just the file itself, they're
some metadata encoded in there also. The File Attachment consists of
a bunch of \0 deliminated strings, so when you look at the decoded
data you might not see what you expect.

Because I generally only care about the attachment data itself, I use
a different decoding scheme where instead of storing the results in a
string, I store it in an array of strings where the last element
contains the decoded data. This only works because the file
attachments I'm importing do not contain \0's
 
S

S.Y.M. Wong-A-Ton

Yes, it is a long road to take to arrive at what you want to achieve...

Thank you for listing the link and the issues you've had with this. I'm sure
others will benefit from your information.
 

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