Hi,
I've just created an account with infopath dev platform. I have been working with infopath for the past 2 years and have been resolving most of my issues from this forum. Thanks for the great help offered here. Its been really useful to me. I am currently faced with an issue that i am finding difficult resolving. I've created an infopath administrator approved form which i successfully published to my SharePoint Server. The Submit button on the form has custom code that post content to SharePoint Newsfeed.Find the snippet of the code below:
public void submitBtn_Clicked(object sender, ClickedEventArgs e)
{
string recepientType = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:typeOfRec", NamespaceManager).Value;
if (recepientType=="1")
{
SPWeb.Equals;
ClientContext clientContext = new ClientContext("http://my");
string cUser = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:cUser", NamespaceManager).Value;
string msg = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:mess", NamespaceManager).Value;
string url = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:url", NamespaceManager).Value;
string accountName = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:recMail", NamespaceManager).Value;
SocialFeedManager socialMgr = new SocialFeedManager(clientContext);
Microsoft.SharePoint.Client.User theUser = clientContext.Web.EnsureUser(cUser);
string userDisplayName = SPContext.Current.Web.EnsureUser(cUser).Name;
clientContext.Load(theUser);
var post = new SocialPostCreationData();
post.ContentText = "Sent an E-Recognition on behalf of " + userDisplayName + " to @{0} ";
post.ContentItems = new[]
{
new SocialDataItem
{
ItemType = SocialDataItemType.User,
AccountName = accountName
}
};
post.Attachment = new SocialAttachment() { AttachmentKind = SocialAttachmentKind.Image, Uri = url };
ClientResult<SocialThread> resultThread = socialMgr.CreatePost(null, post);
//post.ContentText = msg;
clientContext.ExecuteQuery();
}// Write your code here.
}
Issue:
- Currently AllowAnonymousImpersonation for the web application has been set to false. When this property is set to true the submit button on the form generates unauthorized errors. Currently all post sent to a newsfeed are made by the application pool account for the web application. Now i want to be able to modify the code so that post can be made from context of the user that submits the form.
- The form submits ok when run by the site collection administrator. However when site members click the submit button, they receive the warning prompt below
" Warning
There has been an error while processing the form.
Click OK to resume filling out the form. You may want to check your form data for errors.
Hide error details
An entry has been added to the Windows event log of the server.
Log ID:5337
Correlation ID:33cc719d-125c-90f5-500a-d273f2eb830f" "
4/12/2016 13:08:27.32 w3wp.exe (contoso:0x4220) 0x2A80 InfoPath Forms Services Runtime - Business Logic m0jq Warning Business logic failed due to an exception. (User: 0#.w|contoso\user, Form Name: recog, IP: , Request: http://contoso/sites/dev/_layouts/15/FormServer.aspx?XsnLocation=http://contoso/sites/dev/FormServerTemplates/recog.xsn&SaveLocation=http://contoso/sites/dev/form&ClientInstalled=false&DefaultItemOpen=1&Source=http://contoso/sites/dev/form/Forms/AllItems.aspx, Form ID: urn:schemas-microsoft-com:office:infopath:recog:-myXSD-2016-04-01T01-35-12, Type: SPException, Exception Message: The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again. The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.) 33cc719d-125c-90f5-500a-d273f2eb830f
04/12/2016 13:08:27.32 w3wp.exe (contoso:0x4220) 0x2A80 InfoPath Forms Services Runtime - Business Logic m0yi Medium Exception thrown from business logic event listener: Microsoft.SharePoint.SPException: The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again. ---> System.Runtime.InteropServices.COMException: The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again. at Microsoft.SharePoint.Library.SPRequestInternalClass.UpdateMembers(String bstrUrl, UInt32 dwObjectType, String bstrObjId, Guid& pguidScopeId, Int32 lGroupID, Int32 lGroupOwnerId, Object& pvarArrayAdd, Object& pvarArrayAddIds, Object& pvarArrayLoginsRemove, Object& pvarArrayIdsRemove, Boolean bRemoveFromCurrentScopeOnly, Boolean bSendEmail) at Microsoft.SharePoint.Library.SPRequest.UpdateMem... 33cc719d-125c-90f5-500a-d273f2eb830f
04/12/2016 13:08:27.32* w3wp.exe (contoso:0x4220) 0x2A80 InfoPath Forms Services Runtime - Business Logic m0yi Medium ...bers(String bstrUrl, UInt32 dwObjectType, String bstrObjId, Guid& pguidScopeId, Int32 lGroupID, Int32 lGroupOwnerId, Object& pvarArrayAdd, Object& pvarArrayAddIds, Object& pvarArrayLoginsRemove, Object& pvarArrayIdsRemove, Boolean bRemoveFromCurrentScopeOnly, Boolean bSendEmail) --- End of inner exception stack trace --- at Microsoft.SharePoint.SPGlobal.HandleCanaryValidationException(COMException comEx) at Microsoft.SharePoint.Library.SPRequest.UpdateMembers(String bstrUrl, UInt32 dwObjectType, String bstrObjId, Guid& pguidScopeId, Int32 lGroupID, Int32 lGroupOwnerId, Object& pvarArrayAdd, Object& pvarArrayAddIds, Object& pvarArrayLoginsRemove, Object& pvarArrayIdsRemove, Boolean bRemoveFromCurrentScopeOnly, Boolean bSendEmail) at Microsoft.SharePoint.SPUserCollection.Upda... 33cc719d-125c-90f5-500a-d273f2eb830f
04/12/2016 13:08:27.32* w3wp.exe (contoso:0x4220) 0x2A80 InfoPath Forms Services Runtime - Business Logic m0yi Medium ...teMembers(Object objUpdateInfo, Object objAddIds, Object objRemoveLogins, Object objRemoveIds, Boolean fSendEmail) at Microsoft.SharePoint.SPUserCollection.AddCollection(SPUserInfo[] addUsersInfo, IEnumerable`1 addUsers) at Microsoft.SharePoint.SPWeb.EnsureUser(String logonName) at recog.FormCode.submitBtn_Clicked(Object sender, ClickedEventArgs e) in c:\Users\spadmin\AppData\Local\Temp\2\Vsta\9feaabae2255422e87be6b17acf3233d\FormCode.cs:line 51 at Microsoft.Office.InfoPath.Server.Util.DocumentReliability.InvokeBusinessLogic(Thunk thunk) at Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonEventHost.FireClickedEvent(Document document, ClickedEventArgs args) at Microsoft.Office.InfoPath.Server.DocumentLifetime.OMExceptionManager.CallFormCodeWithExceptionHandlin... 33cc719d-125c-90f5-500a-d273f2eb830f
04/12/2016 13:08:27.32* w3wp.exe (contoso:0x4220) 0x2A80 InfoPath Forms Services Runtime - Business Logic m0yi Medium ...g(UserMessages userMessages, OMCall d) 33cc719d-125c-90f5-500a-d273f2eb830f
04/12/2016 13:08:27.34 w3wp.exe (contoso:0x4220) 0x2A80 InfoPath Forms Services Runtime m0ib Medium Not persisting state for request due to previous errors. Form Template: urn:schemas-microsoft-com:office:infopath:recog:-myXSD-2016-04-01T01-35-12 33cc719d-125c-90f5-500a-d273f2eb830f
04/12/2016 13:08:27.34 w3wp.exe (contoso:0x4220) 0x2A80 SharePoint Server State Service 8kfs Medium The StateManager is disposing and calling ReleaseLockedStates() (Count=0) 33cc719d-125c-90f5-500a-d273f2eb830f
04/12/2016 13:08:27.34 w3wp.exe (contoso:0x4220) 0x2A80 SharePoint Foundation Monitoring b4ly Medium Leaving Monitored Scope (Request (POST:http://contoso:80/sites/dev/_layouts/15/Postback.FormServer.aspx)). Execution Time=151.121441412247 33cc719d-125c-90f5-500a-d273f2eb830f
I need help fine tuning the code to eliminate the above issues. Thank you.