I'm trying to programmatically upload an forms template from web application to Central admin. Basically i'm trying to perform "Upload Form Template" functionality in infopath forms services using the following code. If I run the code in a console application it works fine but the same code is not working if I execute under sharepoint context through Webpart code. I'm getting

System.SecurityException access denied error.

I'm running the code with elevated priveleges. The form template file is first downloaded to a temp folder(c:\users\administrator\AppData\Local\Temp) and then I'm uploading the file from this path. thanks in advance for your reply.

2 Answers
2

I do not think it is possible even manually (less programmatically) if you trying to replace a template in use. The Infopath templates are published, not uploaded.

Even for fresh new template I am still in doubt (never tried myself and have no desire to tempt the server integrity by doing this) that it is a proper way - to upload templates instead of their publishing.

I created it as a console application and invoked the exe using process class.
–
KannanSep 14 '12 at 9:11

Did you have to manually copy over the dll associated with the template? Also, did you load SharePoint Management Shell with the process class and then use the uploadtemplate command?
–
Meyer DenneySep 14 '12 at 17:43