473,327 Members | 1,952 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,327 software developers and data experts.

Urgent: Outlook with VB.net

Hi,
i'm trying to retreive the appointments from different profiles of
outlook.
My outlook has 3 profiles created.('Sample1','Sample2','Sample3')
my form contains 3 buttons.each one for each profile.
so when user clicks on a button my code has to show the appointments
for that particular profile that was given there.
i wrote a small procedure for that
here's the code:
----------------------------
Private Sub btnProfile1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnProfile1.Click
olProfile("Sample1")
End Sub

Private Sub btnProfile2_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnProfile2.Click
olProfile("Sample2")
End Sub

Private Sub btnProfile3_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnProfile3.Click
olProfile("Sample3")
End Sub
//This is the procedure....
Private Sub olProfile(ByVal profile As String)
MsgBox("Generating for the profile:" & profile)

Dim appProfile As Outlook.Application = New
Outlook.Application()
Dim nsProfile As Outlook.NameSpace =
appProfile.GetNamespace("mapi")

nsProfile.Logon(profile, , False, True)
Dim fldrProfile As Outlook.MAPIFolder =
nsProfile.GetDefaultFolder(Outlook.OlDefaultFolder s.olFolderCalendar)
Dim aProfile As Outlook.Items = fldrProfile.Items
Dim aptProfile As Outlook.AppointmentItem
Dim iProfile As Integer
MsgBox("Appointment Information from the profile" & profile)
MsgBox(aProfile.Count)
aptProfile = aProfile.GetFirst

For iProfile = 0 To aProfile.Count - 1
MsgBox("Subject:" & aptProfile.Subject & vbCrLf & "
Location:" & aptProfile.Location & vbCrLf & "Start Time:" &
aptProfile.Start & vbCrLf & " End Time:" & aptProfile.End)
aptProfile = aProfile.GetNext
Next
nsProfile.Logoff()
appProfile = Nothing
nsProfile = Nothing
aProfile = Nothing
aptProfile = Nothing

End Sub

----------------------------------------
When i click on one of button it's showing the appointments for that
profile.If i click another button then also it's working fine.
HERE's the problem:
From then onwards if i click any button it's showing the previous
profile's appointments only,irrespective of the button.
here i was caught....how to get rid of this...?
Is there any way to check whether outlook application was launched or
not...if so with what profile??
Can anyone please help me....
Thanks in advance...

Srinivas
Nov 20 '05 #1
1 1710
srinivas,
For starters you are not really releasing the Outlook objects!
appProfile = Nothing
nsProfile = Nothing
aProfile = Nothing
aptProfile = Nothing
End Sub
Remember in .NET we have the GC, setting an object to Nothing, does exactly
that it sets it to Nothing. The GC will at its leisure release the object
(more importantly the COM object). This will cause Outlook to "remain" open,
hence you are getting the same session...

Instead of setting the (COM) objects to Nothing, you should call
ReleaseComObject (in a loop) for each of your COM Objects (objects returned
from Outlook).

See: System.Runtime.InteropServices.Marshal.ReleaseComO bject

This will ensure that the Outlook COM objects are released allowed Outlook
to close. However I do not have multiple profiles to try your sample on...

The following site has a plethora of articles on using Outlook from .NET.

http://www.microeye.com/resources/res_outlookvsnet.htm

Although not necessarily .NET both of these have a lot of Outlook
programming examples & information:

http://www.outlookcode.com/
http://www.slipstick.com/dev/index.htm

Hope this helps
Jay

"srinivas" <sr************@bharatmail.com> wrote in message
news:e9**************************@posting.google.c om... Hi,
i'm trying to retreive the appointments from different profiles of
outlook.
My outlook has 3 profiles created.('Sample1','Sample2','Sample3')
my form contains 3 buttons.each one for each profile.
so when user clicks on a button my code has to show the appointments
for that particular profile that was given there.
i wrote a small procedure for that
here's the code:
----------------------------
Private Sub btnProfile1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnProfile1.Click
olProfile("Sample1")
End Sub

Private Sub btnProfile2_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnProfile2.Click
olProfile("Sample2")
End Sub

Private Sub btnProfile3_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnProfile3.Click
olProfile("Sample3")
End Sub
//This is the procedure....
Private Sub olProfile(ByVal profile As String)
MsgBox("Generating for the profile:" & profile)

Dim appProfile As Outlook.Application = New
Outlook.Application()
Dim nsProfile As Outlook.NameSpace =
appProfile.GetNamespace("mapi")

nsProfile.Logon(profile, , False, True)
Dim fldrProfile As Outlook.MAPIFolder =
nsProfile.GetDefaultFolder(Outlook.OlDefaultFolder s.olFolderCalendar)
Dim aProfile As Outlook.Items = fldrProfile.Items
Dim aptProfile As Outlook.AppointmentItem
Dim iProfile As Integer
MsgBox("Appointment Information from the profile" & profile)
MsgBox(aProfile.Count)
aptProfile = aProfile.GetFirst

For iProfile = 0 To aProfile.Count - 1
MsgBox("Subject:" & aptProfile.Subject & vbCrLf & "
Location:" & aptProfile.Location & vbCrLf & "Start Time:" &
aptProfile.Start & vbCrLf & " End Time:" & aptProfile.End)
aptProfile = aProfile.GetNext
Next
nsProfile.Logoff()
appProfile = Nothing
nsProfile = Nothing
aProfile = Nothing
aptProfile = Nothing

End Sub

----------------------------------------
When i click on one of button it's showing the appointments for that
profile.If i click another button then also it's working fine.
HERE's the problem:
From then onwards if i click any button it's showing the previous
profile's appointments only,irrespective of the button.
here i was caught....how to get rid of this...?
Is there any way to check whether outlook application was launched or
not...if so with what profile??
Can anyone please help me....
Thanks in advance...

Srinivas

Nov 20 '05 #2

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

Similar topics

3
by: gani | last post by:
hi, how to get the fullpath of created IsolatedStorage directory. thanks. -- gani
1
by: Chirag Malvi | last post by:
hello all, I am developing the web application using ASP.net and VS.2003 IDE. here is the situation which i want to implement. 1) User is browsing some webform. I want to trap this event....
13
by: scorpion53061 | last post by:
Very urgent and I am very close but need a little help to get me over the edge........ I need to write these columns to a html file with each row containing these columns (seperated by breaks)....
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
6
by: DraguVaso | last post by:
Hi, I have files I need to read, which contains records with a variable lenght. What I need to do is Copy a Part of such a File to a new File, based on the a Begin- and End-record. I used...
1
by: Liam.M | last post by:
HEY GUYS, need some urgent help here....I am querying my database based on a DueDate field...and want to send an automated email to anyone that falls within two months PRIOR to this "DueDate",...
4
by: Adrian Parker | last post by:
We've suddenly started getting a problem with a call to clear the contents of a DataTable. This is on a live customer site that's been working fine until yesterday. As far as we know they've not...
2
by: keri | last post by:
Please help. I have a database I built but have not used for ages. When I have come to make some changes today in VBA I get the error cannot find project or library I have references to ...
1
by: vicky2007 | last post by:
Hi, I am a Student, and I have a Query related to software developing in "ASP.NET 2.0 with C# " and the problem is:- 1)In ASP.net 2.0 with C#, I am developing a software which has a...
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...
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: 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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.