Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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) { }

share|improve this question
    
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. –  Kannan Feb 14 '12 at 23:33
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
    
I created it as a console application and invoked the exe using process class. –  Kannan Sep 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 Denney Sep 14 '12 at 17:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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