InfoPath SharePoint Web Service Submit Button

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/my:preferred_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!
 
Z

Zhang Haiguang

Please reference the following codes:
CredentialCache cache = new CredentialCache();
cache.Add( listUrl, "NTLM", new NetworkCredential( username, password) );
listsservice.Credentials = cache;

And please create the CredentialCache according the auth schema of your
sharepoint server, it is maybe NTLM, or Basic, and so on..
Please reference the following article:
http://dotnetjunkies.com/Article/6B31D299-347C-4B85-82C5-954546165C80.dcik

InfoJet Service
InfoPath Web Form
[http://www.infojetsoft.com]
 
C

Charles Simpson

Thanks very much for the information and help. I'm trying to work this all
out but I should have stated in my previous post that I'm not really a
developer (other than a little scripting). We are on an Active Directory
domain using NTLM authentication single sign-on. I'm hoping to get this
finished by the 22nd (deadline).

I'm assuming that I put this code that you provided:

CredentialCache cache = new CredentialCache();
cache.Add( listUrl, "NTLM", new NetworkCredential( username, password) );
listsservice.Credentials = cache;


In place of my code:

listsservice.Credentials = System.Net.CredentialCache.DefaultCredentials


If the above is not correct, let me know please. When I place your code in
place of mine, I now get some errors that say that the following are not
declared:

CredentialCache
cache
listUrl
NetworkCredential


Here is a full copy of the code behind my form at this point:

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
CredentialCache cache = new CredentialCache();
cache.Add( listUrl, "NTLM", new NetworkCredential(username,
password) );
listsservice.Credentials = cache;

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/my:preferred_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


Zhang Haiguang said:
Please reference the following codes:
CredentialCache cache = new CredentialCache();
cache.Add( listUrl, "NTLM", new NetworkCredential( username, password) );
listsservice.Credentials = cache;

And please create the CredentialCache according the auth schema of your
sharepoint server, it is maybe NTLM, or Basic, and so on..
Please reference the following article:
http://dotnetjunkies.com/Article/6B31D299-347C-4B85-82C5-954546165C80.dcik

InfoJet Service
InfoPath Web Form
[http://www.infojetsoft.com]
 
Z

Zhang Haiguang

Yes, you are right, the code maybe likes the following:

Imports System.Net
listsservice = New lists.Lists
listsservice.PreAuthenticate = true
CredentialCache cache = New CredentialCache
cache.Add( New Uri( listsservice.Url ), "NTLM", New
NetworkCredential(username, password) )
listsservice.Credentials = cache
 
C

Charles Simpson

Zhang. thanks for helping me on this.

I have the following errors:

1. 'CredentialCache' is a type and cannot be used as an expression
2. 'System.Net.Cache' is a namespace and cannot be used as an expression
3. 'Add' is not a member of 'Cache'
4. 'System.Net.Cache' is a namespace and cannot be used as an expression

Now my code looks like this:

Imports System
Imports Microsoft.Office.Interop.InfoPath.SemiTrust
Imports System.Xml
Imports System.Net


' 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
'CredentialCache cache = new CredentialCache();
'cache.Add( listUrl, "NTLM", new NetworkCredential(username,
password) );
'listsservice.Credentials = cache;

listsservice = New lists.Lists
listsservice.PreAuthenticate = True
CredentialCache(Cache = New CredentialCache)
Cache.Add(New Uri(listsservice.Url), "NTLM", New
NetworkCredential("username", "password"))
listsservice.Credentials = Cache

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/my:preferred_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


I have the following errors:

1. 'CredentialCache' is a type and cannot be used as an expression
2. 'System.Net.Cache' is a namespace and cannot be used as an expression
3. 'Add' is not a member of 'Cache'
4. 'System.Net.Cache' is a namespace and cannot be used as an expression
 
Z

Zhang Haiguang

Hi,

Please check the line:

CredentialCache(Cache = New CredentialCache)

It's seemed that it should be:
CredentialCache Cache = New CredentialCache

Sorry, I'm not know well the language VB.NET.
 
C

Charles Simpson

Still got the same issues. Should I ask over in the VB.NET forum/group? I'm
afraid that when I mention InfoPath, SharePoint, Active Directory that they
will tell me that I'm in the wrong group.
 
S

S.Y.M. Wong-A-Ton

It looks like you're having code access security issues. Have you already
tried giving your form full trust and signing it with a digital certificate?
---
S.Y.M. Wong-A-Ton


Charles Simpson said:
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/my:preferred_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!
 
C

Charles Simpson

Thanks for the information.

1. How do I give the form "full trust?" Is this something that I need to
do on the server? How?

2. Sign with a certificate? Is this something that I need to purchase or
just one of those self-signing certs?

Thanks!

S.Y.M. Wong-A-Ton said:
It looks like you're having code access security issues. Have you already
tried giving your form full trust and signing it with a digital certificate?
---
S.Y.M. Wong-A-Ton


Charles Simpson said:
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/my:preferred_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!
 
S

S.Y.M. Wong-A-Ton

1. In InfoPath, go to Tools > Form Options > Security tab. Uncheck
Automatically determine security level, select Full Trust, check Sign this
form, and select a certificate. Also see
http://office.microsoft.com/en-au/infopath/HP011053381033.aspx?pid=CH011097171033

2. If your forms are used internally on an Intranet, you can install
Certificate Services that comes with Windows Server 2003 and issue your own
certificates; no need to purchase certificates. Self-signing certs are for
testing purposes.
---
S.Y.M. Wong-A-Ton


Charles Simpson said:
Thanks for the information.

1. How do I give the form "full trust?" Is this something that I need to
do on the server? How?

2. Sign with a certificate? Is this something that I need to purchase or
just one of those self-signing certs?

Thanks!

S.Y.M. Wong-A-Ton said:
It looks like you're having code access security issues. Have you already
tried giving your form full trust and signing it with a digital certificate?
---
S.Y.M. Wong-A-Ton


Charles Simpson said:
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/my:preferred_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!
 
C

Charles Simpson

Thanks. I was able to do everything in your post except select a certificate.

I installed Certificate Services on the Server. I set the form to "Full
Trust" but when I click the Select Certificate button, no certificates are
displayed in the box.

S.Y.M. Wong-A-Ton said:
1. In InfoPath, go to Tools > Form Options > Security tab. Uncheck
Automatically determine security level, select Full Trust, check Sign this
form, and select a certificate. Also see
http://office.microsoft.com/en-au/infopath/HP011053381033.aspx?pid=CH011097171033

2. If your forms are used internally on an Intranet, you can install
Certificate Services that comes with Windows Server 2003 and issue your own
certificates; no need to purchase certificates. Self-signing certs are for
testing purposes.
---
S.Y.M. Wong-A-Ton


Charles Simpson said:
Thanks for the information.

1. How do I give the form "full trust?" Is this something that I need to
do on the server? How?

2. Sign with a certificate? Is this something that I need to purchase or
just one of those self-signing certs?

Thanks!

S.Y.M. Wong-A-Ton said:
It looks like you're having code access security issues. Have you already
tried giving your form full trust and signing it with a digital certificate?
---
S.Y.M. Wong-A-Ton


:

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/my:preferred_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!
 
C

Charles Simpson

Do I need to copy the .crt file from the server and store it on my local PC
somewhere?

Charles Simpson said:
Thanks. I was able to do everything in your post except select a certificate.

I installed Certificate Services on the Server. I set the form to "Full
Trust" but when I click the Select Certificate button, no certificates are
displayed in the box.

S.Y.M. Wong-A-Ton said:
1. In InfoPath, go to Tools > Form Options > Security tab. Uncheck
Automatically determine security level, select Full Trust, check Sign this
form, and select a certificate. Also see
http://office.microsoft.com/en-au/infopath/HP011053381033.aspx?pid=CH011097171033

2. If your forms are used internally on an Intranet, you can install
Certificate Services that comes with Windows Server 2003 and issue your own
certificates; no need to purchase certificates. Self-signing certs are for
testing purposes.
---
S.Y.M. Wong-A-Ton


Charles Simpson said:
Thanks for the information.

1. How do I give the form "full trust?" Is this something that I need to
do on the server? How?

2. Sign with a certificate? Is this something that I need to purchase or
just one of those self-signing certs?

Thanks!

:

It looks like you're having code access security issues. Have you already
tried giving your form full trust and signing it with a digital certificate?
---
S.Y.M. Wong-A-Ton


:

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/my:preferred_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!
 
S

S.Y.M. Wong-A-Ton

You can import a certificate into a local certificate store by going to Tools
Options, clicking on Internet Options, then on the Content tab, and then on
the Certificates button. To import a certificate, click on the Import button,
and after a few instructions select the Personal store to put the certificate
into.

Before you do all of this, though, did you test to see whether giving the
form full trust and signing it with a self-signed cert (Create Certificate
button on Security tab in Form Options) solved the security issues you were
having?
---
S.Y.M. Wong-A-Ton


Charles Simpson said:
Do I need to copy the .crt file from the server and store it on my local PC
somewhere?

Charles Simpson said:
Thanks. I was able to do everything in your post except select a certificate.

I installed Certificate Services on the Server. I set the form to "Full
Trust" but when I click the Select Certificate button, no certificates are
displayed in the box.

S.Y.M. Wong-A-Ton said:
1. In InfoPath, go to Tools > Form Options > Security tab. Uncheck
Automatically determine security level, select Full Trust, check Sign this
form, and select a certificate. Also see
http://office.microsoft.com/en-au/infopath/HP011053381033.aspx?pid=CH011097171033

2. If your forms are used internally on an Intranet, you can install
Certificate Services that comes with Windows Server 2003 and issue your own
certificates; no need to purchase certificates. Self-signing certs are for
testing purposes.
---
S.Y.M. Wong-A-Ton


:

Thanks for the information.

1. How do I give the form "full trust?" Is this something that I need to
do on the server? How?

2. Sign with a certificate? Is this something that I need to purchase or
just one of those self-signing certs?

Thanks!

:

It looks like you're having code access security issues. Have you already
tried giving your form full trust and signing it with a digital certificate?
---
S.Y.M. Wong-A-Ton


:

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/my:preferred_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!
 
C

Charles Simpson

It would not allow me to give the form full trust without a certificate. But
I was able to give it Domain Trust and I tried the form and it works!

Thanks so very much for your help on this! I will still try to do the
certificate because I want to learn how to do it.

S.Y.M. Wong-A-Ton said:
You can import a certificate into a local certificate store by going to Tools
Options, clicking on Internet Options, then on the Content tab, and then on
the Certificates button. To import a certificate, click on the Import button,
and after a few instructions select the Personal store to put the certificate
into.

Before you do all of this, though, did you test to see whether giving the
form full trust and signing it with a self-signed cert (Create Certificate
button on Security tab in Form Options) solved the security issues you were
having?
---
S.Y.M. Wong-A-Ton


Charles Simpson said:
Do I need to copy the .crt file from the server and store it on my local PC
somewhere?

Charles Simpson said:
Thanks. I was able to do everything in your post except select a certificate.

I installed Certificate Services on the Server. I set the form to "Full
Trust" but when I click the Select Certificate button, no certificates are
displayed in the box.

:

1. In InfoPath, go to Tools > Form Options > Security tab. Uncheck
Automatically determine security level, select Full Trust, check Sign this
form, and select a certificate. Also see
http://office.microsoft.com/en-au/infopath/HP011053381033.aspx?pid=CH011097171033

2. If your forms are used internally on an Intranet, you can install
Certificate Services that comes with Windows Server 2003 and issue your own
certificates; no need to purchase certificates. Self-signing certs are for
testing purposes.
---
S.Y.M. Wong-A-Ton


:

Thanks for the information.

1. How do I give the form "full trust?" Is this something that I need to
do on the server? How?

2. Sign with a certificate? Is this something that I need to purchase or
just one of those self-signing certs?

Thanks!

:

It looks like you're having code access security issues. Have you already
tried giving your form full trust and signing it with a digital certificate?
---
S.Y.M. Wong-A-Ton


:

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/my:preferred_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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top