Become a Columnist Microsoft Exchange Site Microsoft Support SiteMSDN Exchange Site

   

Subscribe to OutlookExchange
Anderson Patricio
Ann Mc Donough
Bob Spurzem
Brian Veal
Catherine Creary
Cherry Beado
Colin Janssen
Collins Timothy Mutesaria
Drew Nicholson
Fred Volking
Glen Scales
Goran Husman
Guy Thomas
Henrik Walther
Jason Sherry
Jayme Bowers
John Young
Joyce Tang
Justin Braun
Konstantin Zheludev
Kristina Waters
Kuang Zhang
Mahmoud Magdy
Martin Tuip
Michael Dong
Michele Deo
Mitch Tulloch
Nicolas Blank
Pavel Nagaev
Ragnar Harper
Ricardo Silva
Richard Wakeman
Russ Iuliano
Santhosh Hanumanthappa
Steve Bryant
Steve Craig
Todd Walker
Tracey J. Rosenblath
 
 
Private Sub AddNewStoreEvent(fFileSpecified)
    On Error Resume Next
   
    Dim i
    Dim cn
    Dim rEvent
    Dim strEvent
    Dim strGuid
	Dim strBaseUrl
	Dim strEventRegistrationName
	Dim objStream

    strEvent = obArgs.Item(3)
	' Separate the event folder from the event registration name	
	SeperateParentFldFromEvtRegName strEvent, strBaseUrl, strEventRegistrationName
 
    Set cn = CreateObject("ADODB.Connection")
    Set rEvent = CreateObject("ADODB.Record")

	' Create the connection
    cn.Provider = "exoledb.datasource"
    cn.ConnectionString = strBaseUrl
    cn.Open
	If Err.Number <> 0 Then
		WScript.Echo "Error Opening Connection : " & Err.Number & " " & Err.Description & vbCrLf
		Exit Sub
	End If
    
    cn.BeginTrans
    rEvent.Open strEvent, cn, 3, 0     ' adModeReadWrite, adCreateNonCollection
	If Err.Number <> 0 Then
		WScript.Echo "Error Opening Record : " & Err.Number & " " & Err.Description & vbCrLf
		Exit Sub
	End If

	If fFileSpecified Then
		Set objStream = CreateObject("ADODB.Stream")

		objStream.Open rEvent, , 4		' adOpenStreamFromRecord
		If Err.Number <> 0 Then
			WScript.Echo "Error Opening Stream on Record : " & Err.Number & " " & Err.Description & vbCrLf
			Exit Sub
		End If

		objStream.Charset = "ascii"
		objStream.LoadFromFile aPropValues(ndxScriptUrl)
		If Err.Number <> 0 Then
			WScript.Echo "Error Loading Stream From File : " & Err.Number & " " & Err.Description & vbCrLf
			Exit Sub
		End If

		objStream.Close
		If Err.Number <> 0 Then
			WScript.Echo "Error Closing Stream On File : " & Err.Number & " " & Err.Description & vbCrLf
			Exit Sub
		End If

		' get the DAV:href for the binding. The script url is now the binding url itself
		' as we have streamed in the file to the event binding
		aPropValues(ndxScriptUrl) = rEvent.Fields.Item("DAV:href").Value
	End If

	aPropValues(ndxContentClass) = "urn:content-class:storeeventreg"
    With rEvent.Fields
		' Add the binding properties======================
		For i = BeginBindingProps To EndBindingProps
			If aPropValues(i) <> "" Then
				.Item(aPropNames(i)) = aPropValues(i)
				If Err.Number <> 0 Then
					WScript.Echo "Error Adding " & aPropShortNames(i) & " : " & Err.Number & " " & Err.Description & vbCrLf
					Exit Sub
				End If
			End If
		Next

		'Add Sink props =============================
		For i = BeginSinkProps to EndSinkProps
			If aPropValues(i) <> "" Then
				.Item(aPropNames(i)) = aPropValues(i)
				If Err.Number <> 0 Then
					WScript.Echo "Error Adding " & aPropShortNames(i) & " : " & Err.Number & " " & Err.Description & vbCrLf
					Exit Sub
				End If
			End If
		Next
		if aPropValues(8) <> "" then
			rEvent.fields.item(aPropNames(8)) = cdate(aPropValues(8))
		end if	
		if aPropValues(9) <> "" then
			rEvent.fields.item(aPropNames(9)) = cdate(aPropValues(9))
		end if	
		if aPropValues(7) <> "" then
			rEvent.fields.item(aPropNames(7)) = Cint(aPropValues(7))
		end if		
		WScript.Echo "New Event Binding created:" & vbCrLf & "Event: " & aPropValues(ndxEventMethod) & vbCrLf & "Sink:  " & aPropValues(ndxSinkClass) & vbCrLf & "FullBindingUrl: " & strEvent & vbCrLf
		
        .Update
		If Err.Number <> 0 Then
			WScript.Echo "Error Updating Props : " & Err.Number & " " & Err.Description & vbCrLf
			Exit Sub
		End If

    End With

    cn.CommitTrans
	If Err.Number <> 0 Then
		WScript.Echo "Error Commiting Transaction : " & Err.Number & " " & Err.Description & vbCrLf
		Exit Sub
	End If

End Sub

Disclaimer: Your use of the information contained in these pages is at your sole risk. All information on these pages is provided "as is", without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by Stephen Bryant or Pro Exchange. OutlookExchange.Com, Stephen Bryant and Pro Exchange shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.

Copyright Stephen Bryant 2008