FormsService UploadFormTemplate Method throws Access denied error - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

FormsService UploadFormTemplate Method throws Access denied error

Last post 02-05-2012 07:32 PM by kannabirank. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 02-04-2012 06:31 AM

    FormsService UploadFormTemplate Method throws Access denied error

    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();
    }


    Kannan
    Filed under:
  • 02-05-2012 12:30 PM In reply to

    Re: FormsService UploadFormTemplate Method throws Access denied error

    I haven't used this web service, and I don't know if it's the cause of your issue, but does that Console.ReadLine() need to be there?  Would it accomplish anything in your webpart?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-05-2012 04:07 PM In reply to

    Re: FormsService UploadFormTemplate Method throws Access denied error

    Console.ReadLine() is just an example. Ignore that line.

    I'm not sure if I need to run this code with farm admin privilege within my web application???

    Kannan
  • 02-05-2012 06:58 PM In reply to

    Re: FormsService UploadFormTemplate Method throws Access denied error

    Ok, and are you saying that the code works in loading the template from C:\Users\Administrator\AppData\Local\Temp\expensereport.xsn when you run it from the console, but not in a webpart?  I'd think it's very likely that the ShP server process wouldn't have access to the Administrator temp folder.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-05-2012 07:32 PM In reply to

    Re: FormsService UploadFormTemplate Method throws Access denied error

    Hi Jimmy,

    Could you tell me how to give permission to the process for that folder?

    Kannan
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.