Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / February 2007

Tip: Looking for answers? Try searching our database.

VB question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
steve@verizon.net - 24 Feb 2007 20:51 GMT
I need to translate the C# (below) to VB.(this is related to my longer
post from Friday).
So far i can't get past the first line.  I tried adding the following
to the OnLoad event of my project:
(i also added these imports)

Imports System.Xml
Imports System.Xml.XPath

Dim myNav As XPathNavigator = MainDataSource.CreateNavigator()

which doesn't compile because MainDataSource is undefined, which makes
sense, since it's not.
My question:  what is MainDataSource?  Where does it come from?

thanks!

code is from site:

http://enterprise-solutions.swits.net/infopath2007/article.php?t=programmaticall
y-add-item-sharepoint-calendar-infopath&c=infopath2007


XPathNavigator root = MainDataSource.CreateNavigator();

// Retrieve the values for the calendar item
string title = root.SelectSingleNode("my:myFields/my:title",
NamespaceManager).Value;
string location = root.SelectSingleNode("my:myFields/my:location",
NamespaceManager).Value;
string startDate = root.SelectSingleNode("my:myFields/my:startDate",
NamespaceManager).Value;
string startTime = root.SelectSingleNode("my:myFields/my:startTime",
NamespaceManager).Value;
string endDate = root.SelectSingleNode("my:myFields/my:endDate",
NamespaceManager).Value;
string endTime = root.SelectSingleNode("my:myFields/my:endTime",
NamespaceManager).Value;

XPathNavigator batch = DataSources["EventCAML"].CreateNavigator();

// Set the title
batch.SelectSingleNode("/Batch/Method/Field[@Name='Title']",
NamespaceManager).SetValue(title);

// Set the location
batch.SelectSingleNode("/Batch/Method/Field[@Name='Location']",
NamespaceManager).SetValue(location);

// Set the start date
batch.SelectSingleNode("/Batch/Method/Field[@Name='EventDate']",
NamespaceManager).SetValue(string.Format("{0}T{1}Z", startDate,
startTime));

// Set the end date
batch.SelectSingleNode("/Batch/Method/Field[@Name='EndDate']",
NamespaceManager).SetValue(string.Format("{0}T{1}Z", endDate,
endTime));

// Submit the item details to the web service to update the calendar
DataConnections["Web Service Submit"].Execute();
S.Y.M. Wong-A-Ton - 24 Feb 2007 22:24 GMT
What version of InfoPath are you using? MainDataSource in InfoPath 2007 is
the same as DOM in the old InfoPath 2003 object model. So you need to use
thisXDocument.DOM if you're using InfoPath 2003. I think it's the same in
both C# and VB (I do not usually write VB.NET code, so do not know for sure).
---
S.Y.M. Wong-A-Ton

> I need to translate the C# (below) to VB.(this is related to my longer
> post from Friday).
[quoted text clipped - 55 lines]
> // Submit the item details to the web service to update the calendar
> DataConnections["Web Service Submit"].Execute();
steve@verizon.net - 25 Feb 2007 05:20 GMT
Thanks for taking the time to answer my post.

Yes! I'm using 2003, so that explains the mystery!  I'm looking for
something that doesn't exist.
No wonder i couldn't find it.  So i guess my next quest is to figure
out how to use "DOM" in this situation.
that helps a lot.  at least now i have a clue.

thanks again,

steve

On Feb 24, 5:24 pm, S.Y.M. Wong-A-Ton
<SYMWongA...@discussions.microsoft.com> wrote:
> What version of InfoPath are you using?MainDataSourcein InfoPath 2007 is
> the same as DOM in the old InfoPath 2003 object model. So you need to use
[quoted text clipped - 65 lines]
>
> - Show quoted text -
S.Y.M. Wong-A-Ton - 25 Feb 2007 06:19 GMT
No problem. If it is of any help, I just wrote a JScript/VBScript version of
the article for SharePoint 2003 and InfoPath 2003
(http://enterprise-solutions.swits.net/infopath2003/article.php?t=programmaticall
y-add-item-sharepoint-2003-calendar-infopath-2003-script&c=infopath2003
).
I cannot write articles for all the "flavors" of code, so I skipped writing
one for the .NET version of InfoPath 2003, but the article should give you an
idea of how to go about things when using SharePoint 2003, since more people
have been struggling with the conversion from 2007 to 2003.
---
S.Y.M. Wong-A-Ton

> Thanks for taking the time to answer my post.
>
[quoted text clipped - 79 lines]
> >
> > - Show quoted text -
steve@verizon.net - 25 Feb 2007 16:32 GMT
On Feb 25, 1:19 am, S.Y.M. Wong-A-Ton
<SYMWongA...@discussions.microsoft.com> wrote:
> No problem. If it is of any help, I just wrote a JScript/VBScript version of
> the article for SharePoint 2003 and InfoPath 2003
[quoted text clipped - 93 lines]
>
> - Show quoted text -

thanks again - that helped, i think i'm close now .....  I took a shot
at translating to VB.NET (below) - it compiles now, but i get a
runtime error:
on this line:

           batch.selectSingleNode("/Batch/Method/
Field[@Name='Title']").text = title

the error is:

System.MissingMemberException
Public member 'selectSingleNode' on type 'DOMDocument50Wrapper' not
found.
  at
Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o,
Type objType, String name, Object[] args, String[] paramnames,
Boolean[] CopyBack)
  at Absences_Request.Absences_Request.OnLoad(DocReturnEvent e) in C:
\my_data\Visual Studio Projects\Absences Request\FormCode.vb:line 253
  at
Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent
pEvent)

MainCalendar is my CAML data connection.

It seems like my the XPath statement is wrong in this statement:  /
Batch/Method/Field[@Name='Title']").text = title

Looks ok to me - but it doesn't work...

if anybody has any ideas that would be great.

steve

           Dim title As String
           Dim startDate As String
           Dim endDate As String

           startDate = thisXDocument.DOM.selectSingleNode("//
my:startDate").text
           endDate = thisXDocument.DOM.selectSingleNode("//
my:returnDate").text

           Dim batch
           batch = thisXDocument.DataObjects("MainCalendar").DOM
           title = "testing - ignore"
           ' Set the title
           batch.selectSingleNode("/Batch/Method/
Field[@Name='Title']").text = title
           ' Set the start date
           batch.selectSingleNode("/Batch/Method/
Field[@Name='Begin']").text = startDate

           ' Set the end date
           batch.selectSingleNode("/Batch/Method/
Field[@Name='End']").text = endDate

           ' Submit the item details to the web service to update the
calendar
           thisXDocument.DataAdapters("SubmitToCalendar").Submit()
S.Y.M. Wong-A-Ton - 25 Feb 2007 19:16 GMT
Try declaring batch as IXMLDOMDocument and see if that helps.

I also see that you changed the names of the attributes in the batch XML?
The adding of the event might fail, but we'll cross that bridge when we get
there.
---
S.Y.M. Wong-A-Ton

> On Feb 25, 1:19 am, S.Y.M. Wong-A-Ton
> <SYMWongA...@discussions.microsoft.com> wrote:
[quoted text clipped - 156 lines]
> calendar
>             thisXDocument.DataAdapters("SubmitToCalendar").Submit()
steve@verizon.net - 25 Feb 2007 21:45 GMT
wow!  YES, defining it as IXMLDOMDocument got me past that problem.

I changed the names to 'end' and 'begin' because those are the names
on the Events list i have in SharePoint.
they should match, right?

I"m down to the last line - the submit -
thisXDocument.DataAdapters("SubmitToCalendar").Submit() - gets the
following error (i'm running it in Preview mode)

System.MethodAccessException
Attempt to access the method failed.
  at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters,
CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean
verifyAccess)
  at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters,
CultureInfo culture, Boolean verifyAccess)
  at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters,
CultureInfo culture)
  at System.Reflection.MethodBase.Invoke(Object obj, Object[]
parameters)
  at
Microsoft.VisualBasic.CompilerServices.LateBinding.FastCall(Object o,
MethodBase method, ParameterInfo[] Parameters, Object[] args, Type
objType, IReflect objIReflect)
  at
Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object
o, Type objType, String name, Object[] args, String[] paramnames,
Boolean[] CopyBack, Boolean IgnoreReturn)
  at
Microsoft.VisualBasic.CompilerServices.LateBinding.LateCall(Object o,
Type objType, String name, Object[] args, String[] paramnames,
Boolean[] CopyBack)
  at Absences_Request.Absences_Request.OnLoad(DocReturnEvent e) in C:
\my_data\Visual Studio Projects\Absences Request\FormCode.vb:line 264
  at
Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper

On Feb 25, 2:16 pm, S.Y.M. Wong-A-Ton
<SYMWongA...@discussions.microsoft.com> wrote:
> Try declaring batch as IXMLDOMDocument and see if that helps.
>
[quoted text clipped - 167 lines]
>
> - Show quoted text -
S.Y.M. Wong-A-Ton - 26 Feb 2007 08:16 GMT
The error is telling me that .NET cannot invoke the Submit method. Perhaps
the method cannot be accessed/seen on the object.

Try declaring the DataAdapter explicitly, like in:

Dim adpt As WebServiceAdapter2 =
thisXDocument.DataAdapters("SubmitToCalendar")

and then call the Submit, like in:

adpt.Submit()

Regarding the name changes: When you create a list, SharePoint uses a list
schema. And the names defined in the schema differ from what you specify at
the front-end. But let me know whether your name changes work, since I'm no
SharePoint expert.
---
S.Y.M. Wong-A-Ton

> wow!  YES, defining it as IXMLDOMDocument got me past that problem.
>
[quoted text clipped - 210 lines]
> >
> > - Show quoted text -
steve@verizon.net - 27 Feb 2007 03:40 GMT
On Feb 26, 3:16 am, S.Y.M. Wong-A-Ton
<SYMWongA...@discussions.microsoft.com> wrote:
> The error is telling me that .NET cannot invoke the Submit method. Perhaps
> the method cannot be accessed/seen on the object.
[quoted text clipped - 232 lines]
>
> - Show quoted text -

Success!  Declaring the data adapter did the trick.  I also had to
change the names of the variables
as you suggested - i understand it now. Thanks so much for the help on
this - never would have gotten
it to work otherwise.  really helped me out.

In case someone out there needs to do the same thing, here's the
complete VB.NET code:

steve

           '
           ' VB.NET code to automatically create an entry in a
SharePoint Event List
           '
           '
           Dim title As String
           Dim startDate As String
           Dim endDate As String

           startDate = thisXDocument.DOM.selectSingleNode("//
my:startDate").text
           endDate = thisXDocument.DOM.selectSingleNode("//
my:returnDate").text

           Dim batch As IXMLDOMDocument

       ' MainCalendar is the Recieve Data Connection w/ the CAML file
connected

           batch = thisXDocument.DataObjects("MainCalendar").DOM
           title =  "title text"
           ' Set the title
           batch.selectSingleNode("Batch/Method/
Field[@Name='Title']").text = title
           ' Set the start date
           batch.selectSingleNode("/Batch/Method/
Field[@Name='EventDate']").text = startDate

           ' Set the end date
           batch.selectSingleNode("/Batch/Method/
Field[@Name='EndDate']").text = endDate

           ' Submit the item details to the web service to update the
calendar -
           ' SubmitToCalender is a Data Connnection with the web
service defined to it
           '
           Dim adpt As WebServiceAdapter2 =
thisXDocument.DataAdapters("SubmitToCalendar")
           adpt.Submit()
S.Y.M. Wong-A-Ton - 27 Feb 2007 23:28 GMT
Glad to hear you finally got it to work! And glad I could help.
---
S.Y.M. Wong-A-Ton

> On Feb 26, 3:16 am, S.Y.M. Wong-A-Ton
> <SYMWongA...@discussions.microsoft.com> wrote:
[quoted text clipped - 286 lines]
> thisXDocument.DataAdapters("SubmitToCalendar")
>             adpt.Submit()

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.