Hi,
I'm trying to programmatically upload an forms template 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");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
Console.Write("Press Enter to Continue");
Console.ReadLine();
}