Problems with adding new global view programmatically - Outlook 2003 Addin

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,


I am developing an addin in c#.NET (for Outlook 2003), that will allow the
user to copy view settings from one folder to another. To do so, i am coping
the source folder's viewstyle (XML) to a new global
view(olViewSaveOptionAllFoldersOfType as SaveOption), that i am adding and
applying to the target folder. It worls ok the first time, but when i click
on the add-in button second time, the target folder's view is not set to my
global view. On debugging, i noticed that when i have added a new global
view, on the source folder's views collection, this does not seem to appear
on the target folder's views collection and thus i am not able to set it.

But on finishing the execution, if i go via View -> Arrange By -> Current
View on the target folder, the new view is there. And also, the first time i
execute teh add-in, the new global view is indeed appearing on the target
folder's list. I am totally confused as to why this is happenning. There
seems to be some problems with refreshing. Can somebody help me out here??


Thanks in advance.

Regards,

Laks
 
Yes, it does.

Here is the code

Views views = srcFolder.Views;
View newView= views.Add("My Global
View",OlViewType.olTableView,OlViewSaveOption.olViewSaveOptionAllFoldersOfTy
pe);
newView.XML = srcFolder.CurrentView.XML;
newView.Save();
if(targetFolder.Views["My Global View"] !=null)
{
targetFolder.Views["My Global View"].Apply();
}


Thanks and Regards,
Laks
 
Outlook does cache a number of things in memory and doesn't refresh the
cache while you are holding references to the objects. See if purging all
your references and releasing the objects completely by calling the garbage
collector and then getting your objects again makes any difference. The fact
that the view is there after code execution ends (after everything has been
released) makes me think this might be a related problem.
 
Hi,



Thanks a lot Ken. I have released all the references and have called the
GC.Collect(), now it seems to work.Why i say it seems to work and not it
does is because i am trying to manipulate with the views at two places in
the code. It does work at one place and does not work for the other. Here's
the detailed problem.



I want to copy the view settings of Folder A to Folder B and C, so I create
a Global View [olViewSaveOptionAllFoldersOfType] say "My View 1" with the
view properties of Folder A's CurrentView and set it to Folder A, Folder B
and Folder C via my add-in. Now when I check from Outlook, the "My View 1"
has been set on Folder A, B and C. But when I check the properties of "My
View 1" on A, B and C, I find that on Folder B and C, the view is global
i.e. has a SaveOption = olViewSaveOptionAllFoldersOfType but on Folder A, it
has the SaveOption as olViewSaveOptionThisFolderEveryone .[ Can anybody
explain this behaviour? ]



Next, the same action performed by the user can be done multiple times
causing "My View 2", "My View 3",... "My View N" to get accumulated on the
view list and during the course of time some of these would become unused.
So i try to garbage collect the unused views by removing all the unused
views and sorting and renaming the existing views so that they are always in
order. Now till removal of unused views, there are no problems. But when I
try to rename the views by deleting the view with the old name and adding a
view with the new name and setting all the folders that used the old view to
the new view (- is there a better/any other way to do this??), I find that
the old view has been removed on Folder A's view list but not on B and C's.
So when i restart Outlook, the deleted view is there in Folder A's list
too!!! I have tried releasing all references and getting them again but to
no avail.



Thanks and Regards,

Laks





Ken Slovak said:
Outlook does cache a number of things in memory and doesn't refresh the
cache while you are holding references to the objects. See if purging all
your references and releasing the objects completely by calling the garbage
collector and then getting your objects again makes any difference. The fact
that the view is there after code execution ends (after everything has been
released) makes me think this might be a related problem.




Yes, it does.

Here is the code

Views views = srcFolder.Views;
View newView= views.Add("My Global
View",OlViewType.olTableView,OlViewSaveOption.olViewSaveOptionAllFoldersOfTy
pe);
newView.XML = srcFolder.CurrentView.XML;
newView.Save();
if(targetFolder.Views["My Global View"] !=null)
{
targetFolder.Views["My Global View"].Apply();
}


Thanks and Regards,
Laks
 
I haven't had much success in trying to use global view settings and
applying them to all folders using code. I usually end up creating the views
specifically in each folder using olViewSaveOptionThisFolderEveryone as the
save option.
 
Back
Top