Webview pane displayed using commandbar button

Add-in Express™ Support Service
That's what is more important than anything else

Webview pane displayed using commandbar button
 
BR Diamond




Posts: 23
Joined: 2007-04-18

What I am trying to do is to have an Outlook Explorer commandbar button that allows the user to show/hide an adxform as a webview. The command bar button is only visible when the the current folder is a mail folder. The adxform ExplorerItemTypes is set to <Mail>. The adxform should never be visible for any folders containing non mail items.

The commandbar button should display the webview pane when clicked down, and return the view to regular Outlook mail explorer view when clicked up again. The form is cached <OneInstanceForAllFolders> so the same instance is displayed whenever the commandbar button is clicked, no matter what particular folder is current.

I searched the archives here and think the following two topics contain samples of what I need. However they are both in C which I don't have.

How to display Form from the Command Button
http://www.add-in-express.com/forum/read.php?FID=5&TID=1788&MID=8550&phrase_id=383069#message8550

Switching from WebViewPane to regular outlook explorer view and back?http://www.add-in-express.com/forum/read.php?FID=5&TID=1752&MID=8736&phrase_id=541673#message8736

I am using
VB.net 2005 Express edition
Add-in Express 2007 for .Net version 3.5.1875 Standard
Outlook 2003

I would really appreciate a VB.net sample combining the techniques in the above examples. Would that be possible?


Thanks

BRD

Posted 20 Aug, 2007 04:31:36 Top
Fedor Shihantsov


Add-in Express team


Posts: 1188
Joined: 2005-01-11
Hello BRD,

The following HOWTOs should help you:
Controlling the visibility of a form in an Advanced Form Region.
How to move a custom .NET form embedded into Outlook window from one form region to another

See also: Visual Basic .NET HOWTOs

P.S. We always do our best to answer your forum requests as soon as possible. However, we apply the rule "first in first out" with Premium Support Service subscribers taking priority. Please understand it may take us some time to do research on the issue. Please be assured we will let you know as soon as the best possible solution is found.
Posted 20 Aug, 2007 13:38:28 Top
BR Diamond




Posts: 23
Joined: 2007-04-18

Thanks Fedor

Some really useful things in both of those examples.

My problem arises when the ExplorerLayout for my adxform is set to WebViewPane, as this layout seems to behave differently from the other layouts.

If you open the Visibility example and change the ExplorerLayout for the adxOlFormsCollectionItem1 from BottomSubPane to WebViewPane using the ADXOlFormsCollection Editor, then the problem is reproduced. The form displays as a webview pane no problem, but when it is hidden, it leaves just a blank white pane in its place. What I want to be able to do is display the same normal explorer view that shows when the ExplorerLayout for the adxOlFormsCollectionItem1 is anything except WebViewPane.

How can I do this?

Many thanks

BRD








Posted 21 Aug, 2007 04:47:07 Top
Fedor Shihantsov


Add-in Express team


Posts: 1188
Joined: 2005-01-11
You need clear a folder webview properties and refresh folder after changing of ExplorerLayout.

You can see a similar code in the Layouts sample.
See the ADXUtils.SetExplorerLayout method

[CODE]...
If NeedClearFolderWebViewProperties Then
OutlookUtils.ClearFolderWebViewProperties(currentFolder)
OutlookUtils.RefreshCurrentFolder(explorer)
...
End If
...
Posted 22 Aug, 2007 05:16:29 Top
BR Diamond




Posts: 23
Joined: 2007-04-18

Thanks Fedor

Sorry for late reply but I'm still having difficulties with this.
I'm not changing the ExplorerLayout, the form is always set to WebPaneView.

I'm just trying to toggle the form's visibility when the user clicks an explorer commandbar button. Even if I clear the folder webview properties when I hide the form, I still just get a white screen in its place (after a split second flash of Outbox folder in RefreshCurrentFolder sub.) What is the process to get regular explorer view back after hiding WebPaneView? It's doing me head in!

I'm trying to put a sub like following in the addin module to run on the explorer commandbar button click event

Private Sub ResetFolderViewFromWebpane()
Dim explorer As Outlook.Explorer = OutlookApp.ActiveExplorer()
Dim currentFolder As Outlook.MAPIFolder = explorer.CurrentFolder
sample.OutlookUtils.ClearFolderWebViewProperties(currentFolder)
sample.OutlookUtils.RefreshCurrentFolder(explorer)
AdxOlFormsCollectionItem1.ApplyTo(explorer)
End Sub

What's wrong with it?

regards

BRD


Posted 26 Aug, 2007 20:01:44 Top
Fedor Shihantsov


Add-in Express team


Posts: 1188
Joined: 2005-01-11
You need to disable AdxOlFormsCollectionItem1 or set ExplorerLayout to Unknown before you call ResetFolderViewFromWebpane. In the opposite case, ADXOlFormsManager will set WebView properties anew.

Also you should not call AdxOlFormsCollectionItem1.ApplyTo(explorer) when you hides ADXOlForm.

Try this and let me know about the result.

Please note:
Changing the ADXOlFormsCollectionItem.Enable, .Cached, .FormClassName properties causes deleting all forms created by the ADXOlFormsCollectionItem.

Changing ADXOlFormsCollectionItem.InspectorItemTypes, ExplorerItemTypes, ExplorerMessageClasses, ExplorerMessageClass, InspectorMessageClasses, InspectorMessageClass, FolderNames, FolderName properties causes deleting non-visible forms.

Changing the ADXOlFormsCollectionItem.ExplorerLayout, InspectorLayout properties causes changing the Layout for all visible forms.

Changing the ADXOlFormsCollectionItem.Splitter, Tag properties doesn't do anything for the currently visible forms. You will see the Splitter changed when OutlookFormsManager shows the form anew.
Posted 27 Aug, 2007 06:36:12 Top
BR Diamond




Posts: 23
Joined: 2007-04-18

Fedor

Great guidance, thank you. I can now switch between Webview and regular explorer view on a single folder no problem. However a couple of issues have now cropped up

1) Sometimes folders are set to point to other websites by default. For example, the PersonalFolders root folder is set by default to show the html page outlooktoday. I can display my form while I'm in PersonalFolders root, but when I hide my form, I get returned to an regular folder view not the webpage. So how do I clear my webview pane and return a folder to a webview pointing to another url? Is there a way to store the default url of a folder that is originally set to display a web site and return to it when my form is hidden?

and leading on from this

2) Clearing webview properties on a single folder is fine but when the
ADXOlFormsCollectionItem ExplorerFormat is changed to Unknown, all folders showing this form are affected. Obviously I need to clear web view on all folders that are affected (or as above reset to other urls as necessary). So I need to be able to loop through all folders, resetting them either to point to their original urls or to show regular outlook explrer views. How do I start going about that??

kind regards



Posted 27 Aug, 2007 19:52:46 Top
Fedor Shihantsov


Add-in Express team


Posts: 1188
Joined: 2005-01-11
BRD,

ADXOlFormsManager does not replace a folder view to the WebViewPane layout when a folder has a webpage view (not the regular folder view).

For such folders, you should clear WebView-related properties yourself. Also, you should save Folder.WebViewUrl if you want restore this property after hidding ADXOlForm.

ADXOlFormsManager replaces a regular folder view and saves theFolder.WebViewUrl properties for this folders. But ADXOlFormsManager restores this properties in the DoAddinBeginShutdown event only.

Also you can see related topics:
Programmatically Collapse Outlook Panel

Switching from WebViewPane to regular outlook explorer view and back

Did this answer make clear the situation?
Posted 28 Aug, 2007 10:19:08 Top
BR Diamond




Posts: 23
Joined: 2007-04-18

Thanks Fedor.

If I understand you correctly, I will have to loop through all the mailfolders (and all their subfolders) every time I hide my webpane, setting the WebViewUrl and WebViewOn properties to their original values for any folder that was set to show webpage by default. So what's the best way to quickly get all the folders that are being affected? How does ADXOlFormsManager get which folders need to be cleared so quickly? And can I use the same method?

To store the urls to return to I'm thinking of using a hashtable with the folder ID as a key and url as value (initialized on startup). Then when I hide my webpane, when I loop through all mail folders affected by the ExplorerLayout change I can check if the folder ID appears in the hashtable, and if so run a seperate sub to override the change back to regular Outlook listview for that folder.

But since this loop through the folders is going to be triggered everytime I hide my form, it's going to have to be very quick. Please can you guide me on the most efficient way to achieve this?
Posted 30 Aug, 2007 20:33:30 Top
Fedor Shihantsov


Add-in Express team


Posts: 1188
Joined: 2005-01-11
Sorry, ADXOlFormsManager is not designed for disabling the WebViewPane layout dynamically.

You can use the AddinModule.RegistryKey.ADXXOL.WebView registry key to get all processed folders.


public class ADXOlFolderWebViewProperties
{
    public static void Restore()
    {
        RegistryKey ModuleKey = null;
        RegistryKey WebViewKey = null;
        RegistryKey ADXXOLKey = null;
        try
        {
            string RegistryKey = AddinModule.CurrentInstance.RegistryKey;
            ModuleKey = Registry.CurrentUser.OpenSubKey(RegistryKey, true);
            if (ModuleKey != null)
            {
                ADXXOLKey = ModuleKey.OpenSubKey(ADXOlFolderWebViewProperties.ADXXOLKey, true);
                if (ADXXOLKey != null)
                {
                    WebViewKey = ADXXOLKey.OpenSubKey(ADXOlFolderWebViewProperties.WebViewKey, true);
                    if (WebViewKey != null)
                    {
                        string[] names = WebViewKey.GetValueNames();
                        for (int i = 0; i < names.Length; i++)
                        {
                            object FolderObj = null;
                            try
                            {
                                try
                                {
                                    string[] values = (string[])WebViewKey.GetValue(names[i]);
                                    if (values != null)
                                    {
                                        FolderObj = FolderFromEntryID(AddinModule.CurrentInstance.HostApplication, names[i]);
                                        if (FolderObj != null)
                                        {
                                            if (CompareStrings(values[0], ADXOlFolderWebViewProperties.EMPTYConst))
                                                values[0] = String.Empty;

                                            SetWebView(FolderObj, values[0], Convert.ToBoolean(values[1]));
                                        }
                                    }
                                }
                                catch
                                {
                                }
                            }
                            finally
                            {
                                if (FolderObj != null)
                                {
                                    Marshal.ReleaseComObject(FolderObj);
                                    FolderObj = null;
                                }
                                WebViewKey.DeleteValue(names[i]);
                            }
                        }
                    }
                }

                if (ModuleKey.OpenSubKey(ADXOlFolderWebViewProperties.ADXXOLKey) != null)
                {
                    //ModuleKey.DeleteSubKeyTree(ADXXOLKey);
                }
            }
        }
        finally
        {
            if (ModuleKey != null) ModuleKey.Close();
            if (WebViewKey != null) WebViewKey.Close();
            if (ADXXOLKey != null) ADXXOLKey.Close();
        }
    }

    private static string ADXXOLKey = "ADXXOL";
    private static string WebViewKey = "WebView";
    private static string EMPTYConst = "EMPTY";

    private static bool CompareStrings(string str1, string str2)
    {
        if (String.Compare(str1.Trim(), str2.Trim(), true, System.Globalization.CultureInfo.InvariantCulture) == 0)
            return true;
        return false;
    }

    private static object FolderFromEntryID(object OutlookAppObj, string EntryID)
    {
        try
        {
            if (OutlookAppObj != null)
            {
                object OutlookNameSpaceObj = OutlookAppObj.GetType().InvokeMember("GetNamespace", BindingFlags.GetProperty, null, OutlookAppObj, new object[] { "MAPI" });
                try
                {
                    if (OutlookNameSpaceObj != null)
                    {
                        return OutlookNameSpaceObj.GetType().InvokeMember("GetFolderFromID", BindingFlags.InvokeMethod, null, OutlookNameSpaceObj, new object[] { EntryID });
                    }
                    else
                    {
                        return null;
                    }
                }
                finally
                {
                    if (OutlookNameSpaceObj != null)
                    {
                        Marshal.ReleaseComObject(OutlookNameSpaceObj);
                        OutlookNameSpaceObj = null;
                    }
                }
            }
            else
            {
                return null;
            }
        }
        catch
        {
            return null;
        }
    }

    private static void SetWebView(object FolderObj, string WebViewURL, bool WebViewOn)
    {
        try
        {
            if (FolderObj != null)
            {
                FolderObj.GetType().InvokeMember("WebViewURL", BindingFlags.SetProperty, null, FolderObj, new object[] { WebViewURL });
                FolderObj.GetType().InvokeMember("WebViewOn", BindingFlags.SetProperty, null, FolderObj, new object[] { WebViewOn });
            }
        }
        catch
        {
            //"Insufficient permission"
        }
    }
}


Please note, we reserve the right to change the registry key.
Posted 03 Sep, 2007 09:27:22 Top