Sujeewa Ediriweera

February 18, 2012

Accessing secure store service programmatically – part 02 (Impersonation)

Filed under: SharePoint — sujeewa.ediriweera @ 3:41 am
Tags: , , , ,

Over view
Although we have the run with elevated privileges option , In some cases  we need to execute specific functions with specific  user account privileges .Impersonation is very common when we are dealing with SharePoint services.

Solution

Initiate site object with different user token and execute code under nitiated site. You can do following

  • Create impersonate SPWeb object inside impersonated site object.
  • Get impersonate SPContext using impersonated site object.
  • Get impersonate SPServiceContext using impersonated site object.

Prerequisites
You need to have a specific domain account to use as impersonate user. In my case I have setup a Secure Service Store Application key to retrieve impersonate user information

https://sujeewaediriweera.wordpress.com/2012/02/15/accessing-secure-store-service-programmatically-part-01/

Code

Code for Impersonation


Advertisements

February 12, 2012

Accessing InfoPath form data programmatically

Filed under: SharePoint — sujeewa.ediriweera @ 4:57 am
Tags: , , ,

Overview:

In my case I have InfoPath form to capture   First Name, Last Name, and Email of customers. I need to access these values programmatically.

Understanding:

Fields declared in custom InfoPath form are stored as ‘my:{fieldname}’ format .

Field name   Display name XML representation
txtFirstName First Name my:txtFirstName
txtLastName Last Name my:txtLastName
txtEmailAddress Email Address my:txtEmailAddress

Solution:

There are many ways to access InfoPath form.  In this solution we are using following steps to retrieve InfoPath form data.

  • Identify field names and their XML representation
  • Read InfoPath form  item from InfoPath document Library
  • Load  attached InfoPath form’s XML representation  to XmlTextReader
  • Read each node using XmlTextReader and extract user input  based on our requirement

Code:

Source Code : ReadFromInfoPathForm

Out put:

Blog at WordPress.com.