Hi everybody,
I am desparate, I can't get this code to work from an ASP.NET webpage.
Problem is when I try to retrieve contact information and I get to
MyDataRow("Tel.") = MyContact.BusinessTelephoneNumber, My App just hangs.
I think it is because normally a dialog box would open up and say that an external program is trying to "connect" to outlook and if I want to allow it.
Does anybody know a workaround?
Thank you in advance,
MyOutlook = New Outlook.Application
MyNamespace = MyOutlook.GetNamespace("MAPI")
Dim MyOutlookProcess() As Process
MyOutlookProcess = Process.GetProcessesByName("OUTLOOK")
If MyOutlookProcess.Length > 0 Then
MyNamespace.Logon(Nothing, Nothing, True, False)
Else
MyNamespace.Logon(Nothing, Nothing, True, True)
End If
MyContactFolder = MyNamespace.GetFolderFromID(GlobalSettings.SelectedContactFolder)
MyContactDataTable = New DataTable("Kontakten")
MyContactDataTable.Columns.Add(New DataColumn("Select", System.Type.GetType("System.Boolean")))
MyContactDataTable.Columns("Select").AllowDBNull = False
MyContactDataTable.Columns.Add(New DataColumn("Objekt-Nr."))
MyContactDataTable.Columns.Add(New DataColumn("KundenTyp"))
MyContactDataTable.Columns.Add(New DataColumn("Firma"))
MyContactDataTable.Columns.Add(New DataColumn("Strasse"))
MyContactDataTable.Columns.Add(New DataColumn("PLZ"))
MyContactDataTable.Columns.Add(New DataColumn("Ort"))
MyContactDataTable.Columns.Add(New DataColumn("Name"))
MyContactDataTable.Columns.Add(New DataColumn("Geburtstag"))
MyContactDataTable.Columns.Add(New DataColumn("Vorname"))
MyContactDataTable.Columns.Add(New DataColumn("Abteilung"))
MyContactDataTable.Columns.Add(New DataColumn("Tel."))
MyContactDataTable.Columns.Add(New DataColumn("Fax"))
MyContactDataTable.Columns.Add(New DataColumn("Mobil"))
MyContactDataTable.Columns.Add(New DataColumn("Mail"))
MyContactDataTable.Columns.Add(New DataColumn("Internet"))
MyContactDataTable.Columns.Add(New DataColumn("Bemerkungen"))
MyContactDataTable.Columns.Add(New DataColumn("InDB"))
If SelectedInDB = "Nein" Then
SelectedInDB = "N"
Else
SelectedInDB = "J"
End If
For Each MyContact In MyContactFolder.Items
Dim ObjectID As String = ""
Dim InDB As String
Dim KundenTyp As String
Dim PropertyNumber As String
Try
If Not IsNothing(MyContact.ItemProperties("ID").Value) Then
ObjectID = MyContact.ItemProperties("ID").Value
Else
ObjectID = i & "T"
End If
Catch ex As Exception
ObjectID = i & "T"
End Try
Try
If Not IsNothing(MyContact.ItemProperties("InDB").Value) Then
InDB = MyContact.ItemProperties("InDB").Value
Else
InDB = "N"
End If
Catch ex As Exception
InDB = "N"
End Try
Try
If Not IsNothing(MyContact.ItemProperties("KundenTyp").Value) Then
KundenTyp = MyContact.ItemProperties("KundenTyp").Value
Else
KundenTyp = ""
End If
Catch ex As Exception
KundenTyp = ""
End Try
If SelectedKundenTyp = "" Or KundenTyp = SelectedKundenTyp Then
If InDB = SelectedInDB Then
Dim MyDataRow As DataRow
MyDataRow = MyContactDataTable.NewRow
MyDataRow("Select") = False
MyDataRow("Objekt-Nr.") = ObjectID
If KundenTyp.Trim = "" Then
MyDataRow("KundenTyp") = ""
Else
MyDataRow("KundenTyp") = DBKundenTyp.GetKundenTypBeschreibung(KundenTyp)
End If
MyDataRow("Firma") = MyContact.CompanyName
MyDataRow("Strasse") = MyContact.BusinessAddressStreet
MyDataRow("PLZ") = MyContact.BusinessAddressPostalCode
MyDataRow("Ort") = MyContact.BusinessAddressCity
MyDataRow("Name") = MyContact.LastName
MyDataRow("Geburtstag") = MyContact.Birthday
MyDataRow("Vorname") = MyContact.FirstName
MyDataRow("Abteilung") = MyContact.Department
Here it just hangs and nothing happens anymore --> MyDataRow("Tel.") = MyContact.BusinessTelephoneNumber
MyDataRow("Mobil") = MyContact.MobileTelephoneNumber
MyDataRow("Fax") = MyContact.BusinessFaxNumber
MyDataRow("Mail") = MyContact.Email1Address
MyDataRow("Internet") = MyContact.BusinessHomePage
MyDataRow("Bemerkungen") = MyContact.Body
MyDataRow("InDB") = InDB
MyContactDataTable.Rows.Add(MyDataRow)
End If
End If
i += 1
Next
datagrid1.DataSource = MyContactDataTable
datagrid1.DataBind()
Catch ex As Exception
MyNamespace.Logoff()
MyOutlook.Quit()
Exit Sub
Finally
MyNamespace.Logoff()
MyOutlook.Quit()
datagrid1.Visible = True
End Try
/Peace2u
I am desparate, I can't get this code to work from an ASP.NET webpage.
Problem is when I try to retrieve contact information and I get to
MyDataRow("Tel.") = MyContact.BusinessTelephoneNumber, My App just hangs.
I think it is because normally a dialog box would open up and say that an external program is trying to "connect" to outlook and if I want to allow it.
Does anybody know a workaround?
Thank you in advance,
MyOutlook = New Outlook.Application
MyNamespace = MyOutlook.GetNamespace("MAPI")
Dim MyOutlookProcess() As Process
MyOutlookProcess = Process.GetProcessesByName("OUTLOOK")
If MyOutlookProcess.Length > 0 Then
MyNamespace.Logon(Nothing, Nothing, True, False)
Else
MyNamespace.Logon(Nothing, Nothing, True, True)
End If
MyContactFolder = MyNamespace.GetFolderFromID(GlobalSettings.SelectedContactFolder)
MyContactDataTable = New DataTable("Kontakten")
MyContactDataTable.Columns.Add(New DataColumn("Select", System.Type.GetType("System.Boolean")))
MyContactDataTable.Columns("Select").AllowDBNull = False
MyContactDataTable.Columns.Add(New DataColumn("Objekt-Nr."))
MyContactDataTable.Columns.Add(New DataColumn("KundenTyp"))
MyContactDataTable.Columns.Add(New DataColumn("Firma"))
MyContactDataTable.Columns.Add(New DataColumn("Strasse"))
MyContactDataTable.Columns.Add(New DataColumn("PLZ"))
MyContactDataTable.Columns.Add(New DataColumn("Ort"))
MyContactDataTable.Columns.Add(New DataColumn("Name"))
MyContactDataTable.Columns.Add(New DataColumn("Geburtstag"))
MyContactDataTable.Columns.Add(New DataColumn("Vorname"))
MyContactDataTable.Columns.Add(New DataColumn("Abteilung"))
MyContactDataTable.Columns.Add(New DataColumn("Tel."))
MyContactDataTable.Columns.Add(New DataColumn("Fax"))
MyContactDataTable.Columns.Add(New DataColumn("Mobil"))
MyContactDataTable.Columns.Add(New DataColumn("Mail"))
MyContactDataTable.Columns.Add(New DataColumn("Internet"))
MyContactDataTable.Columns.Add(New DataColumn("Bemerkungen"))
MyContactDataTable.Columns.Add(New DataColumn("InDB"))
If SelectedInDB = "Nein" Then
SelectedInDB = "N"
Else
SelectedInDB = "J"
End If
For Each MyContact In MyContactFolder.Items
Dim ObjectID As String = ""
Dim InDB As String
Dim KundenTyp As String
Dim PropertyNumber As String
Try
If Not IsNothing(MyContact.ItemProperties("ID").Value) Then
ObjectID = MyContact.ItemProperties("ID").Value
Else
ObjectID = i & "T"
End If
Catch ex As Exception
ObjectID = i & "T"
End Try
Try
If Not IsNothing(MyContact.ItemProperties("InDB").Value) Then
InDB = MyContact.ItemProperties("InDB").Value
Else
InDB = "N"
End If
Catch ex As Exception
InDB = "N"
End Try
Try
If Not IsNothing(MyContact.ItemProperties("KundenTyp").Value) Then
KundenTyp = MyContact.ItemProperties("KundenTyp").Value
Else
KundenTyp = ""
End If
Catch ex As Exception
KundenTyp = ""
End Try
If SelectedKundenTyp = "" Or KundenTyp = SelectedKundenTyp Then
If InDB = SelectedInDB Then
Dim MyDataRow As DataRow
MyDataRow = MyContactDataTable.NewRow
MyDataRow("Select") = False
MyDataRow("Objekt-Nr.") = ObjectID
If KundenTyp.Trim = "" Then
MyDataRow("KundenTyp") = ""
Else
MyDataRow("KundenTyp") = DBKundenTyp.GetKundenTypBeschreibung(KundenTyp)
End If
MyDataRow("Firma") = MyContact.CompanyName
MyDataRow("Strasse") = MyContact.BusinessAddressStreet
MyDataRow("PLZ") = MyContact.BusinessAddressPostalCode
MyDataRow("Ort") = MyContact.BusinessAddressCity
MyDataRow("Name") = MyContact.LastName
MyDataRow("Geburtstag") = MyContact.Birthday
MyDataRow("Vorname") = MyContact.FirstName
MyDataRow("Abteilung") = MyContact.Department
Here it just hangs and nothing happens anymore --> MyDataRow("Tel.") = MyContact.BusinessTelephoneNumber
MyDataRow("Mobil") = MyContact.MobileTelephoneNumber
MyDataRow("Fax") = MyContact.BusinessFaxNumber
MyDataRow("Mail") = MyContact.Email1Address
MyDataRow("Internet") = MyContact.BusinessHomePage
MyDataRow("Bemerkungen") = MyContact.Body
MyDataRow("InDB") = InDB
MyContactDataTable.Rows.Add(MyDataRow)
End If
End If
i += 1
Next
datagrid1.DataSource = MyContactDataTable
datagrid1.DataBind()
Catch ex As Exception
MyNamespace.Logoff()
MyOutlook.Quit()
Exit Sub
Finally
MyNamespace.Logoff()
MyOutlook.Quit()
datagrid1.Visible = True
End Try
/Peace2u