none
Forcing FileAs to always be uppercase RRS feed

  • Question

  • When I go to save my contact, I want it to always force the "File As" to be in uppercase without the user having to keep doing it each time, so I was wondering if there's like an on saving that I could do something to the following effect in my addin c# program as an event handler:

    contactItem.FileAs = contactItem.FileAs.ToUpper();

    Tuesday, March 5, 2013 6:58 PM

Answers

  • No, there is no way to do that unless you are the one programmatically calling SaveAs.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Tuesday, March 5, 2013 7:33 PM
  • If you call SaveAs programmatically, you can pass whatever you want as a parameter.

    If you want the Save As dialog in Outlook to default the file name (subject based) to be all upper case, I don't think you can do that easily without Windows API hooks.

    Or, as you mentioned, you can modify FileAs/Subject to be upper case to begin with. Not sure if the users will like that...


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Friday, March 8, 2013 5:49 PM

All replies

  • No, there is no way to do that unless you are the one programmatically calling SaveAs.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Tuesday, March 5, 2013 7:33 PM
  • I'm not sure how different is programmically calling SaveAs to my intention of forcing an uppercase FileAs.  My other alternative would be to perform an adhoc utility to loop each contact and uppercase everything in FileAs so long as nobody is in the system.  Just an example of my trying to think outside the box here.
    Wednesday, March 6, 2013 3:41 PM
  • If you call SaveAs programmatically, you can pass whatever you want as a parameter.

    If you want the Save As dialog in Outlook to default the file name (subject based) to be all upper case, I don't think you can do that easily without Windows API hooks.

    Or, as you mentioned, you can modify FileAs/Subject to be upper case to begin with. Not sure if the users will like that...


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Friday, March 8, 2013 5:49 PM
  • In getting back to this question, and since it's becoming a concern for my users, one idea I'm trying to figure how to code is the following in my add-in:

            void fullname_textchanged()
            {
                contactItem.FileAs = contactItem.FileAs.ToUpper();
            }

    I know an existing syntax I have for a command button clicked is:

                this.cmdAddr1.Click += new Microsoft.Office.Interop.Outlook.OlkCommandButtonEvents_ClickEventHandler(cmdAddr1_Click);

    but now I want to detect if the fullname field changed and am rather stuck on finishing this following attempt so far:

                this.fullName.Change += new Microsoft.Office.Interop.Outlook.OlkTextBoxEvents(fullname_textchanged());

    -red squiggly line appears at end indicates:
      Cannot create an instance of the abstract class or interface 'Microsoft.Office.Interop.Outlook.OlkTextBoxEvents'

    any way I can best finish this?


    • Edited by jfalberg Thursday, March 21, 2013 6:23 PM
    Thursday, March 21, 2013 6:21 PM
  • Why not use ContactItem.PropertyChange event?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Thursday, March 21, 2013 6:27 PM
  • You cannot handle anything much for form events than click events, and that's supported in form code using VBScript. In managed code in an addin you should be handling the PropertyChange() event on the item and checking what property was changed.
     
    For any calculated field such as FullName you will get that event firing multiple times. It will fire for FirstName, LastName, and any other component fields of a calculated field.
     
    One question I have is whether you actually want the FileAs to be in all uppercase? I would think most users would hate that. Do you really want all uppercase, wouldn't proper casing be more appropriate?
     
    Lower case: john doe
    Upper case: JOHN DOE
    Proper case: John Doe

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "jfalberg" <=?utf-8?B?amZhbGJlcmc=?=> wrote in message news:d2cde4c4-9c2c-4b8e-8298-fc2ba19fcad7...

    In getting back to this question, and since it's becoming a concern for my users, one idea I'm trying to figure how to code is the following in my add-in:

            void fullname_textchanged()
            {
                contactItem.FileAs = contactItem.FileAs.ToUpper();
            }

    I know an existing syntax I have for a command button clicked is:

                this.cmdAddr1.Click += new Microsoft.Office.Interop.Outlook.OlkCommandButtonEvents_ClickEventHandler(cmdAddr1_Click);

    but now I want to detect if the fullname field changed and am rather stuck on finishing this following attempt so far:

                this.fullName.Change += new Microsoft.Office.Interop.Outlook.OlkTextBoxEvents(fullname_textchanged());

    -red squiggly line appears at end indicates:
      Cannot create an instance of the abstract class or interface 'Microsoft.Office.Interop.Outlook.OlkTextBoxEvents'

    any way I can best finish this?



    Ken Slovak MVP - Outlook
    Thursday, March 21, 2013 6:32 PM
    Moderator
  • The client is requesting the File As to be strictly uppercase, their preference actually.
    Thursday, March 21, 2013 6:34 PM
  • Here's what I have for my code now which is bugging me with an error at the moment:

    at top of class:

    public static Outlook.ContactItem contactItem;

    below in my code:

    contactItem.PropertyChange += new Microsoft.Office.Interop.Outlook.OlkTextBoxEvents_PropertyChangeHandler(fullName_textchanged);

    Error 1 Cannot implicitly convert type 'Microsoft.Office.Interop.Outlook.OlkCommandButtonEvents_ClickEventHandler' to 'Microsoft.Office.Interop.Outlook.ItemEvents_10_PropertyChangeEventHandler'

    function below forces fileas to upper.

     void fullname_textchanged()
            {
                
                contactItem.FileAs = contactItem.FileAs.ToUpper();
            }

    Any correct way I need to correct this?



    • Edited by jfalberg Thursday, March 21, 2013 7:00 PM
    Thursday, March 21, 2013 6:58 PM
  • Your event signature is incorrect - you must use ItemEvents or ItemEvents_10, not OlkTextBoxEvents


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Thursday, March 21, 2013 7:35 PM
  • Update, I at least got the code part to work but I don't believe it's actually work since I notice after I enter or change the fullname field the fileas field still appears with the non-upper text.

                contactItem.PropertyChange += new Microsoft.Office.Interop.Outlook.ItemEvents_10_PropertyChangeEventHandler(fullname_textchanged);

            void fullname_textchanged(string name)
            {
                contactItem.FileAs = contactItem.FileAs.ToUpper();
            }

    Is there something else I'm missing here?

    Essentially I want it so when contact is saved or re-saved then force uppercase automatically on FileAs.
    • Edited by jfalberg Thursday, March 21, 2013 7:48 PM
    Thursday, March 21, 2013 7:36 PM
  • Firstly, you might want to check the old value first to make sure you do not needlessly reste the value.

    Secondly, you can also check the property name argument.

    If you want to update the FileAs property before the contact is saved, why not use the Write event?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!


    Thursday, March 21, 2013 8:15 PM
  • So far the Write event works when I enter new contacts, but how about if I want to correct or update an existing contact, would it be a save event or similar?
    Thursday, March 21, 2013 8:31 PM
  • It should be the same. Are you running into a problem for an existing contact?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Thursday, March 21, 2013 8:36 PM
  • Here's what I now have for my coding:

                contactItem.Write += new Outlook.ItemEvents_10_WriteEventHandler(contactItem_Write);

            void contactItem_Write(ref bool Cancel)
            {
                string fas = contactItem.FileAs.ToUpper();
                contactItem.FileAs = fas;
            }

    I open a new contact, then enter zzz zzz as the fullname, immediately save, then notice in my list view and custom reading pane (region form replacement) that the File As appears as ZZZ, ZZZ but when I change the name to something like zzz zzzy it still stays as ZZZ, ZZZ

    It gets weirder on a separate new contact where I enter zy zy, tab to another field which automatically populates default fileas, then save/close.  List view shows as ZY, ZY but reading pane is actually showing as zy, zy in original lowercase so I wonder if there's anything else I may now be missing here.  reading pane should not be changeable anyways I would think.

    Thursday, March 21, 2013 8:49 PM
  • Reading pane gets updated only when you select another item and come back, there is nothing you can do about that.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Thursday, March 21, 2013 8:52 PM
  • After updating my form add-in with the write function, this is how my view appears.  Notice the fileas column appears in uppercase but in my form region reading pane below it is still appearing as lowercase on the same file.  I'm perplexed as to why this is happening.  Of course if the view has an option to always force display as uppercase then that could solve my client's problem.  Otherwise I will have to perform nightly updates on the fileas field only it seems.

    Friday, March 22, 2013 5:22 PM
  • This is to be expected - the list shows live data, it comes from IMAPITable on the low level.

    The preview pane uses the contact object cached by Outlook. As long as that object is alive and cached, it will display the stale data. You need to make sure your code does not hold any references to the ContactItem object (release it using Marshal.ReleaseComObject and call GC.Collect()) and you also need to select another contact and then reselect the contact for teh preview pane to show the updated data.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Friday, March 22, 2013 5:54 PM
  • In looking at my add-in through debug mode and putting a watch on the contactItem level, I notice that FileAs is truly coming in capitals but what I don't understand is why my form using the generic FileAs field is displaying like the "Subject" or "TaskSubject" or "FullName" fields in lowercase instead.  It gives a misleading that the FileAs is not getting capitalized when it should when looking at the form region itself.
    Friday, March 22, 2013 6:38 PM
  • Are you asking why these properties are not updated to upper case? If yes, it is your responsibility to update these properties.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Friday, March 22, 2013 7:26 PM
  • I think I know what the problem is, but am not sure which advanced property on the form I need to change for this.

    I can see that when I type anything other than the (Lastname, firstname) or (firstname lastname) spelling then it displays desireably as capitalized, but when I do use the (Lastname, firstname) or (firstname lastname) it forces the display to automatically appear in the same case as is in the fullname even though FileAs is truly capitalize, so I wonder which advanced property is controlling that.

    Almost there it seems.

    Friday, March 22, 2013 7:35 PM
  • This is definitely not getting any easier for me.  I see when I edit the FileAs field and change the MatchEntry value to None instead of Complete that it works on a normal contact form, but since this is a form region I am editing, somehow the MatchEntry field is nowhere to be found when I go to advanced properties even after I copy the FileAs field directly from the blank contact form.  Programmatically this field is not coming up in intellisense for any existance of MatchEntry so I don't understand what's going on here.
    Friday, March 22, 2013 8:11 PM
  • Look at the contact with MFCMAPI or OutlookSpy (click IMessage). Do you see any properties that have the wrong value?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Friday, March 22, 2013 8:49 PM
  • Unfortunately I don't have OutlookSpy nor any other tools of such, but this is where I'm at:

    I open a new contact (class Rolodex) and go to Developer tab and Open my form Region.  I can see in the General tab when I right click on the File As field and go to advanced properties, I can change MatchEntry from 1-Complete to 2-None; however, when I go to my custom form region that is open and right click on the copy of the File As field and go to Advanced Properties, I no longer see a property for MatchEntry as an option.

    I tried saving my form region while the File As in the general tab was set to 2-None but that didn't stop my pulldown from deceptively appearing in lowercase while it was truly saved in uppercase which is what we want accomplished.

    Normally I'd be fine with this, but my dictator boss is paranoid that the user would get confused when they see it in lowercase on the form.

    Wednesday, March 27, 2013 5:06 PM
  • OutlookSpy can downloaded from http://www.dimastr.com/outspy/download.htm

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Wednesday, March 27, 2013 5:20 PM
  • I successfully installed OutlookSpy 32-bit and getting back to question I am assuming 0x8034 FileUnder looks correct at least.  Now I need to get MatchEntry property to work as desired on my form region.  I wonder if OutlookSpy or something else can assist me in getting this properly.
    Wednesday, March 27, 2013 5:45 PM
  • You can set any property using ContactItem.PropertyAccessor - pass the DASL name displayed by OutlookSpy (select the property in the IMessage window, look at the DASL edit box.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Wednesday, March 27, 2013 6:43 PM
  • Here's what I get if I understood correctly:

    DASL:
    urn:schemas:contacts:fileas
    or
    http://schemas.microsoft.com/mapi/id/{00062004-0000-0000-C000-000000000046}/8005001F

    OOM:
    FileUnder

    so in my form region add-in, I would add the following syntax?

    contactItem.PropertyAccessor.SetProperty( <string SchemaName>, <object value>);

    so would DASL be the schema name? and I wonder how the 2nd parameter would be if I'm trying to set MatchEntry to 2-None.


    • Edited by jfalberg Wednesday, March 27, 2013 7:19 PM
    Wednesday, March 27, 2013 7:03 PM
  • Or you can just set the ContactItem.FileAs property...

    I am not sure what you mean by "I'm trying to set MatchEntry to 2-None".


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Friday, March 29, 2013 2:36 PM
  • MatchEntry is the property that indicates how the spelling display should match what is already on list.  So if following exists:

    Lyn Zurl
    Zurl, Lyn

    then if the user types in ZURL, LYN then it forces the display to be Zurl, Lyn if MatchEntry is set to 1-Complete, whereas 2-None does not enforce case matching.  

    Friday, March 29, 2013 3:05 PM
  • That is a property of the OlkListBox control, it has nothing to do with the contact itself.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Saturday, March 30, 2013 10:39 PM
  • As an update on this lingering issue I've been having, I at least got it to work by changing the FileAs field from a combobox type to a text type and also setting the initial value of this field to: UCase ( [File As] ) and calculate this formula automatically.  The problem I am now having is if I open the contact form for the first time from another user then go to close without doing anything, it prompts me the following:

    Do you want to save changes?

    Should this following code still suffice in my add-in?

            void contactItem_Write(ref bool Cancel)
            {
                string curText = contactItem.FileAs;
                if (!string.IsNullOrEmpty(curText))
                    contactItem.FileAs = curText.ToUpper();
            }


    Monday, April 8, 2013 4:07 PM
  • I don't think that code will get rid of the prompt - you do change the FileAs property, and that causes the prompt to fire.

    If that is the only code you are running (no bound controls), then the prompt will not be shown.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!


    Monday, April 8, 2013 4:28 PM