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;
try
{
FormTemplate temp = new FormTemplate();
localFormsService = localFarm.Services.GetValue (FormsService.ServiceName);
localFormsService.FormTemplates.UploadFormTemplate
(@"C:\Users\Administrator\AppData\Local\Temp\expensereport.xsn");
} catch (Exception ex) { }