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.

FormsService localFormsService; 
SPFarm localFarm = SPFarm.Local;
Int16 formTemps; 
    FormTemplate temp = new FormTemplate(); 
    localFormsService = localFarm.Services.GetValue (FormsService.ServiceName); 

} catch (Exception ex) { }

  • I have temporarily found a workaround by creating a console application and used a process class to execute the console app from my web part. Feb 14, 2012 at 23:33

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.


Did you try setting the scope of your feature to Farm?

  • I created it as a console application and invoked the exe using process class. Sep 14, 2012 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? Sep 14, 2012 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.