C
Charles Simpson
Hello and thanks for reading!
I have an InfoPath 2003 form stored in SharePoint that is attempting to
update an existing SharePoint list with a new record using the following code:
Imports System
Imports Microsoft.Office.Interop.InfoPath.SemiTrust
Imports System.Xml
' Microsoft Office integration attribute. Identifies the startup class for
the form. Do not modify.
<Assembly: System.ComponentModel.DescriptionAttribute("InfoPathStartupClass,
Version=1.0, Class=iesr.FormCode")>
Namespace iesr
' The namespace prefixes defined in this attribute must remain
synchronized with
' those in the form definition file (.xsf).
<InfoPathNamespace("xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution""
xmlns:s0=""http://schemas.microsoft.com/sharepoint/soap/""
xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-12T15:28:41"" xmlns:xd=""http://schemas.microsoft.com/office/infopath/2003""")> _
Public Class FormCode
Private thisXDocument As XDocument
Private thisApplication As Application
Public Sub _Startup(ByVal app As Application, ByVal doc As XDocument)
thisXDocument = doc
thisApplication = app
' You can add additional initialization code here.
End Sub
Public Sub _Shutdown()
End Sub
' The following function handler is created by Microsoft Office
InfoPath. Do not
' modify the type or number of arguments.
<InfoPathEventHandler(MatchPath:="CTRL7_17",
EventType:=InfoPathEventType.OnClick)> _
Public Sub CTRL7_17_OnClick(ByVal e As DocActionEvent)
' Write your code here.
End Sub
' The following function handler is created by Microsoft Office
InfoPath. Do not
' modify the type or number of arguments.
<InfoPathEventHandler(MatchPath:="CTRL122_5",
EventType:=InfoPathEventType.OnClick)> _
Public Sub CTRL122_5_OnClick(ByVal e As DocActionEvent)
' Write your code here.
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
' The following function handler is created by Microsoft Office
InfoPath. Do not
' modify the type or number of arguments.
<InfoPathEventHandler(MatchPath:="CTRL27_17",
EventType:=InfoPathEventType.OnClick)> _
Public Sub CTRL27_17_OnClick(ByVal e As DocActionEvent)
' Write your code here.
End Sub
' The following function handler is created by Microsoft Office
InfoPath. Do not
' modify the type or number of arguments.
<InfoPathEventHandler(EventType:=InfoPathEventType.OnSubmitRequest)> _
Public Sub FormEvents_OnSubmitRequest(ByVal e As DocReturnEvent)
' If the submit operation is successful, set
' e.ReturnStatus = True
End Sub
Public Function CreateTask(ByVal strFull_x0020_Name As String, _
ByVal strPreferred_x0020_First_x0020_Name
As String) As Integer
Dim listName As String
Dim listsservice As lists.Lists
Dim node As XmlDocument
Dim res As XmlNode
Dim resultError As XmlNode
Dim resultId As XmlNode
listName = "{AA6DF9CC-4CDF-45F0-9BA2-1F4E2521C537}"
listsservice = New lists.Lists
listsservice.Credentials =
System.Net.CredentialCache.DefaultCredentials
node = New XmlDocument
node.LoadXml("" _
+ "<Batch OnError='Continue' ListVersion='1' xmlns=''>" _
+ " <Method ID='1' Cmd='New'>" _
+ " <Field Name='Full_x0020_Name'>" + strFull_x0020_Name +
"</Field>" _
+ " <Field Name='Preferred_x0020_First_x0020_Name'>" +
strPreferred_x0020_First_x0020_Name + "</Field>" _
+ " </Method>" _
+ "</Batch>")
res = listsservice.UpdateListItems(listName, node)
Dim nsmgr As XmlNamespaceManager
nsmgr = New XmlNamespaceManager(res.OwnerDocument.NameTable)
nsmgr.AddNamespace("s",
"http://schemas.microsoft.com/sharepoint/soap/")
nsmgr.AddNamespace("z", "#RowsetSchema")
resultError =
res.SelectSingleNode("s:Result[@ID='1,New']/s:ErrorCode", _
nsmgr)
If (resultError Is Nothing Or _
Convert.ToInt32(resultError.InnerText, 16) <> 0) Then
Return 0
End If
resultId =
res.SelectSingleNode("s:Result[@ID=""1,New""]/z:row/@ows_ID", _
nsmgr)
Return Integer.Parse(resultId.InnerText)
End Function
' The following function handler is created by Microsoft Office
InfoPath. Do not
' modify the type or number of arguments.
<InfoPathEventHandler(MatchPath:="CTRL28_17",
EventType:=InfoPathEventType.OnClick)> _
Public Sub CTRL28_17_OnClick(ByVal e As DocActionEvent)
Dim id As Integer
id = CreateTask( _
thisXDocument.DOM.selectSingleNode("/my:myFields/my:NewEmployeeSection/my:Full_x0020_Name").text, _
thisXDocument.DOM.selectSingleNode("/my:myFields/my:NewEmployeeSection/myreferred_x0020_First_x0020_Name").text)
If (id = 0) Then
thisXDocument.UI.Alert("Failed to create new Employee.")
Else
thisXDocument.UI.Alert("Created new Employee ID " +
id.ToString() + ".")
End If
End Sub
End Class
End Namespace
My data connection is called Lists and is pointing to the SharePoint
lists.asmx?wsdl Web service.
When running the code from Visual Studio 2005 it stops on this line: res =
listsservice.UpdateListItems(listName, node)
And has this error: Request for the permission of type
'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed.
If I run the form from its saved location in SharePoint, I get this error
after I click the button on the form that is setup to create the new task in
the SharePoint list:
Request for the permission of type
'System.Security.Permissions.EnvironmentPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand,
StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Net.CredentialCache.get_DefaultCredentials()
at iesr.FormCode.CreateTask(String strFull_x0020_Name, String
strPreferred_x0020_First_x0020_Name)
at iesr.FormCode.CTRL28_17_OnClick(DocActionEvent e)
at
Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
Any help on this would be appreciated. I’m sorry that this post is so long.
Let me know if you need any additional information. Thanks for your help!
I have an InfoPath 2003 form stored in SharePoint that is attempting to
update an existing SharePoint list with a new record using the following code:
Imports System
Imports Microsoft.Office.Interop.InfoPath.SemiTrust
Imports System.Xml
' Microsoft Office integration attribute. Identifies the startup class for
the form. Do not modify.
<Assembly: System.ComponentModel.DescriptionAttribute("InfoPathStartupClass,
Version=1.0, Class=iesr.FormCode")>
Namespace iesr
' The namespace prefixes defined in this attribute must remain
synchronized with
' those in the form definition file (.xsf).
<InfoPathNamespace("xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution""
xmlns:s0=""http://schemas.microsoft.com/sharepoint/soap/""
xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-02-12T15:28:41"" xmlns:xd=""http://schemas.microsoft.com/office/infopath/2003""")> _
Public Class FormCode
Private thisXDocument As XDocument
Private thisApplication As Application
Public Sub _Startup(ByVal app As Application, ByVal doc As XDocument)
thisXDocument = doc
thisApplication = app
' You can add additional initialization code here.
End Sub
Public Sub _Shutdown()
End Sub
' The following function handler is created by Microsoft Office
InfoPath. Do not
' modify the type or number of arguments.
<InfoPathEventHandler(MatchPath:="CTRL7_17",
EventType:=InfoPathEventType.OnClick)> _
Public Sub CTRL7_17_OnClick(ByVal e As DocActionEvent)
' Write your code here.
End Sub
' The following function handler is created by Microsoft Office
InfoPath. Do not
' modify the type or number of arguments.
<InfoPathEventHandler(MatchPath:="CTRL122_5",
EventType:=InfoPathEventType.OnClick)> _
Public Sub CTRL122_5_OnClick(ByVal e As DocActionEvent)
' Write your code here.
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
' The following function handler is created by Microsoft Office
InfoPath. Do not
' modify the type or number of arguments.
<InfoPathEventHandler(MatchPath:="CTRL27_17",
EventType:=InfoPathEventType.OnClick)> _
Public Sub CTRL27_17_OnClick(ByVal e As DocActionEvent)
' Write your code here.
End Sub
' The following function handler is created by Microsoft Office
InfoPath. Do not
' modify the type or number of arguments.
<InfoPathEventHandler(EventType:=InfoPathEventType.OnSubmitRequest)> _
Public Sub FormEvents_OnSubmitRequest(ByVal e As DocReturnEvent)
' If the submit operation is successful, set
' e.ReturnStatus = True
End Sub
Public Function CreateTask(ByVal strFull_x0020_Name As String, _
ByVal strPreferred_x0020_First_x0020_Name
As String) As Integer
Dim listName As String
Dim listsservice As lists.Lists
Dim node As XmlDocument
Dim res As XmlNode
Dim resultError As XmlNode
Dim resultId As XmlNode
listName = "{AA6DF9CC-4CDF-45F0-9BA2-1F4E2521C537}"
listsservice = New lists.Lists
listsservice.Credentials =
System.Net.CredentialCache.DefaultCredentials
node = New XmlDocument
node.LoadXml("" _
+ "<Batch OnError='Continue' ListVersion='1' xmlns=''>" _
+ " <Method ID='1' Cmd='New'>" _
+ " <Field Name='Full_x0020_Name'>" + strFull_x0020_Name +
"</Field>" _
+ " <Field Name='Preferred_x0020_First_x0020_Name'>" +
strPreferred_x0020_First_x0020_Name + "</Field>" _
+ " </Method>" _
+ "</Batch>")
res = listsservice.UpdateListItems(listName, node)
Dim nsmgr As XmlNamespaceManager
nsmgr = New XmlNamespaceManager(res.OwnerDocument.NameTable)
nsmgr.AddNamespace("s",
"http://schemas.microsoft.com/sharepoint/soap/")
nsmgr.AddNamespace("z", "#RowsetSchema")
resultError =
res.SelectSingleNode("s:Result[@ID='1,New']/s:ErrorCode", _
nsmgr)
If (resultError Is Nothing Or _
Convert.ToInt32(resultError.InnerText, 16) <> 0) Then
Return 0
End If
resultId =
res.SelectSingleNode("s:Result[@ID=""1,New""]/z:row/@ows_ID", _
nsmgr)
Return Integer.Parse(resultId.InnerText)
End Function
' The following function handler is created by Microsoft Office
InfoPath. Do not
' modify the type or number of arguments.
<InfoPathEventHandler(MatchPath:="CTRL28_17",
EventType:=InfoPathEventType.OnClick)> _
Public Sub CTRL28_17_OnClick(ByVal e As DocActionEvent)
Dim id As Integer
id = CreateTask( _
thisXDocument.DOM.selectSingleNode("/my:myFields/my:NewEmployeeSection/my:Full_x0020_Name").text, _
thisXDocument.DOM.selectSingleNode("/my:myFields/my:NewEmployeeSection/myreferred_x0020_First_x0020_Name").text)
If (id = 0) Then
thisXDocument.UI.Alert("Failed to create new Employee.")
Else
thisXDocument.UI.Alert("Created new Employee ID " +
id.ToString() + ".")
End If
End Sub
End Class
End Namespace
My data connection is called Lists and is pointing to the SharePoint
lists.asmx?wsdl Web service.
When running the code from Visual Studio 2005 it stops on this line: res =
listsservice.UpdateListItems(listName, node)
And has this error: Request for the permission of type
'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed.
If I run the form from its saved location in SharePoint, I get this error
after I click the button on the form that is setup to create the new task in
the SharePoint list:
Request for the permission of type
'System.Security.Permissions.EnvironmentPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand,
StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Net.CredentialCache.get_DefaultCredentials()
at iesr.FormCode.CreateTask(String strFull_x0020_Name, String
strPreferred_x0020_First_x0020_Name)
at iesr.FormCode.CTRL28_17_OnClick(DocActionEvent e)
at
Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
Any help on this would be appreciated. I’m sorry that this post is so long.
Let me know if you need any additional information. Thanks for your help!