Is it possible to read from a .config-file in InfoPath SP1?

S

StefanO-nl

In a Web- or Windows-application you use ConfigurationSettings.AppSettings to read from a .config-file. I'd like to do the same in the FormCode.cs-file, but it seems this doesn't work. I've tried to name the file MyForm.xsn.config (where MyForm is the name of the InfoPath C#-project).

Is there a way to use the standard xml-configfile or should I write my own configfile handler?
 
A

Andrew Ma [MSFT]

Have you tried naming it INFOPATH.EXE.CONFIG.
I'm not familiar with how Windows apps handle it, but as far as I know, this
is how it is supposed to work.
Config files are usually per application, not per solution. So the .config
file way might not be how you want to go about this.

You should just save your config settings in some xml file and then attach
it to the solution as a secondary data source. Otherwise you will need to
create a solution as full trust to get it to read files off disk.

--
Andrew J. Ma
Software Test Engineer
Microsoft Office InfoPath
http://blogs.msdn.com/ajma
---------------------------------------
This posting is provided "As Is" with no warranties, and confers no rights.
Use of any included script sample are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
Please do not send email directly to this alias. This alias is for
newsgroup purposes only.
 
M

Matthew Blain \(Serriform\)

Check the value of
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile.

I don't know how InfoPath creates its appdomains, but a custom config file
as Greg suggests is certainly going to work and has less 'appdomain' issues.

--Matthew Blain
http://tips.serriform.com/
 
S

StefanO-nl

Andrew Ma said:
Have you tried naming it INFOPATH.EXE.CONFIG.
Check the value of
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile.

I've checked that value; it was:
@"C:\Program Files\Microsoft Office\OFFICE11\INFOPATH.EXE.config"
So you're right. It's probably not the way I want to proceed... -Although it works fine and I might use it anyway :)

Using a secondary data source isn't the right solution for me as well, because when I publish my form (which is fully trusted btw) it will become part of the xsn-file and this is not what I want either...
 
M

Matthew Blain \(Serriform\)

Yes, it works just fine. If you have it on an HTTP server, it will even be
loaded from the wininet cache and sometimes work offline. (Also sometimes
get out of date if you're editing the file, but that's a rare and
understandable case.)

I wish InfoPath let you have controled caching of secondary data sources
such as config files, as this is a very common scenario.

--Matthew Blain
http://tips.serriform.com/


When adding a data connection (in this case a config.xml file), InfoPath
asks you, at the last step, if you want this file included as part of the
form. I haven't tried it myself, but I believe that if you say "No", that it
will use a hard-coded full path to that resource.

My assumption (not having tried this) is that if the resource is hosted on a
server, as long as the other users have the same path access to that stored
location that the config.xml file does not need to be part of the XSN and
can still be accessed.

If you play with this, please post your findings as I haven't had time to
try it, but am currious if it works as I expect.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



Andrew Ma said:
Have you tried naming it INFOPATH.EXE.CONFIG.
Check the value of
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile.

I've checked that value; it was:
@"C:\Program Files\Microsoft Office\OFFICE11\INFOPATH.EXE.config"
So you're right. It's probably not the way I want to proceed... -Although it
works fine and I might use it anyway :)

Using a secondary data source isn't the right solution for me as well,
because when I publish my form (which is fully trusted btw) it will become
part of the xsn-file and this is not what I want either...
 
S

StefanO-nl

Greg Collins said:
When adding a data connection (in this case a config.xml file),
InfoPath asks you, at the last step, if you want this file included
as part of the form.

Yes, when the secondary datasource isn't a resource file yet, you will be asked if you want to include this file as part of the form and when you say Yes, it will become a resource file.

It works fine using the config.xml as a resource file. It also works if you don't use a resource file but a hard coded path (saying No when asked to include the file as part of the form).

The con of this solution however is that this folder must exist on every client PC. If InfoPath can't find the file, it will display this errormessage:
The following DataObject either cannot be created or cannot be initialized: Config
The query cannot be run for the following DataObject: Config
InfoPath cannot run the specified query.
InfoPath cannot open the following file: Config.xml.
The system cannot find the file specified.

This error is shown both when I remove the resource file (in the first scenario) as well as when I remove the full path in the manifest.xsf (in the second scenario). I've tried several folders for my config.xml-file (same as the xsn-file, c:\program files\microsoft office\office11), but I keep getting this error.

And even if I would solve this problem of finding out what the folder config.xml must be, I have another problem: The error is before the OnLoad-event and therefore can't be catched to show a user friendly error dialog...

I'd expect more support of InfoPath for config-files.
 
M

Matthew Blain \(Serriform\)

Where is the XSN stored?

StefanO-nl said:
Yes, when the secondary datasource isn't a resource file yet, you will be
asked if you want to include this file as part of the form and when you say
Yes, it will become a resource file.
It works fine using the config.xml as a resource file. It also works if
you don't use a resource file but a hard coded path (saying No when asked to
include the file as part of the form).
The con of this solution however is that this folder must exist on every
client PC. If InfoPath can't find the file, it will display this
errormessage:
The following DataObject either cannot be created or cannot be initialized: Config
The query cannot be run for the following DataObject: Config
InfoPath cannot run the specified query.
InfoPath cannot open the following file: Config.xml.
The system cannot find the file specified.

This error is shown both when I remove the resource file (in the first
scenario) as well as when I remove the full path in the manifest.xsf (in the
second scenario). I've tried several folders for my config.xml-file (same as
the xsn-file, c:\program files\microsoft office\office11), but I keep
getting this error.
And even if I would solve this problem of finding out what the folder
config.xml must be, I have another problem: The error is before the
OnLoad-event and therefore can't be catched to show a user friendly error
dialog...
 
M

Matthew Blain \(Serriform\)

How does the form get onto the user's machine? Will each user have a
different config file? If it's a fully trusted form, you could specify any
location you wanted to for a config file. If it's not, what you can do is
limited.
 
Top