473,326 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

VB.NET InfoPath

Hello

I've tried in the InfoPath groups but no luck yet. Here is my situation:

All computers are on an Active Directory domain in the company. I have an
Infopath form stored on the network (in SharePoint) that needs to be able to
update a SharePoint list when a button is clicked.

I got the sample code from a book called "Developing Solutions with
Microsoft InfoPath".

It seems, from the build errors that I'm not able to get the code to run on
the server because of security.

Here is my original VB.NET code and the errors associated with it:

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("InfoPa thStartupClass,
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(Obj ect 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._Butto nEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

Here is my current VB.NET code and the build errors associated with it:

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("InfoPa thStartupClass,
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

Any help would be greatly appreciated! Thanks!
Mar 17 '07 #1
0 2714

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sven Steinacker | last post by:
Hi, XSLT files generated by Microsoft InfoPath applied to an applicable XML file produces quite decent HTML presentations. At least with Mozilla and, of course, IE 6.0 the results look the same...
0
by: Dr. Paul Caesar - CoullByte (UK) Limited | last post by:
Hi all, Have been playing about with web services but unable to achieve what I am wanting and in attempts finding strange problems. I have created a web service for retrieving customer data...
0
by: Pascal Brunot | last post by:
Hi, Running XSDObjectGen (1.4.1.0) on the following Infopath-generated XSD gives an "unexpected error": "Event register full" during generation (exact english error message may differ, i am...
4
by: MJ | last post by:
A question for InfoPath and ASP.NET experts: What do you think about the future of InfoPath and ASP.NET WebForms? Is InfoPath 12 going to replace ASP.NET WebForms? If not, in which types of...
0
by: Cosimo Galasso | last post by:
I'm building a aspx web page with a button control. When the button is clicked the server build an xml string containg the directive to be opened with infopath. When the client receive the file an...
3
by: Jeff Richardson | last post by:
This is a repost from the InfoPath news group. Hi, I am writing a SharePoint application that works with InfoPath forms. When a user submits a completed InfoPath form to a forms library my code...
0
by: Milan | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as empty...
0
by: Sebastian Gingter | last post by:
I have an infopath XML file and want to use XPath queries with the XmlDocument object. The Problem: Every (in my eyes correct) XPath query does return a NULL object. Example: XmlDocument doc =...
0
by: Anni | last post by:
Hi, Can anyone please tell me how do I give same namespace for different infopath forms.? I have an XML formed by an infopath form, the XML is : <?mso-infoPathSolution...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.