How to add readonly fields in outlook contact via plug-in - c#

I have a requirement of adding certain read only fields(once created then it will not change) in existing contacts or while creating new contacts in Outlook through my vsto plug-in. I am able to add user defined fields using ItemProperty and UserProperty:
Outlook.ContactItem newContact = this.Application.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
Outlook.ItemProperty itemProp = newContact.ItemProperties.Add("PermanentID", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olNumber, false, 1);
itemProp.Value = "123123";
newContact.Email1Address = "abc#d.com";
Outlook.UserProperty mailUserProperty = newContact.UserProperties.Add("ID1", Outlook.OlUserPropertyType.olNumber, false, 1);
mailUserProperty.Value = "123345456";
newContact.Save();
This does create fields in the Contact but they are not read only. Is there any way around to create read only fields or adding new properties to the contact item that can be shown within the Contact window?
Any suggestions?

No, sorry to say, but there is no way to prevent the user from editing the values of UserProperty objects.
They are exposed in Outlook and freely editable by the user or any other add-in.
The only possibility I see it creating a custom pane in VSTO, where you show the value of the field 'read-only', but that doesn't prevent the user from actually changing it.

You can add a user property instead. See the UserProperties property of the ContactItem class. To display them in the inspector window you can develop a form region. You are free to display the required information in the read-only way.
See How to: Add a Form Region to an Outlook Add-in Project to get started.

Related

How can I disable To address bar for new created mail item?

I am working with Outlook addin which is perform task for creating new mail item and sent to users.
Now what I want is, I don't want to allow user to add email in To field, in short I need To field to remain disable for user, but I am not getting any way to disable it.
MailApp.Application oApp = new MailApp.Application();
oMailItem =(MailApp.MailItem)oApp.CreateItem(MailApp.OlItemType.olMailItem);
oMailItem.To = "abc#gg.com"; // need to disable this for end user.
oMailItem.Subject = "Xyz";
oMailItem.HTMLBody = "Xyz";
oMailItem.Display(false);
oMailItem.Actions[1].Enabled = false; // it allow index from 1 to 4 which disable reply , reply all, reply to and forward option on current mail but not To field.
Please help to achieve this in my addin. How can I disable To field for end user?
The only way to disable the To field address control is to customize the form design, remove the controls and publish that form definition to that user's Personal Forms library. For more information, see https://learn.microsoft.com/en-ca/office/vba/outlook/concepts/forms/customizing-form-pages-and-form-regions.
In addition to Eric's suggestion, you can try to hook the MailIem.PropertyChange event, and when (and if!) the "To" property is modified, reset it back.
There is no need to customize the built-in Outlook form and then re-publish it. It is a very old technology which is not used any longer by add-in developers.
You can use Outlook form regions and place the form to the Replace-all layout which replaces the whole Outlook form with the form region. Read more about that in the Create Outlook form regions article on MSDN.
Also, you may consider using Add-in Express. They provide the CompleteReplacement layout which also completely replace all pages of any Inspector window.
Note, in both cases, you can use any .net controls for creating a custom UI in Outlook

In Visual Studio how to access the source control history window programmatically?

I am developing a Visual Studio Extension. I need to access the Source Control's History window to check what history items are selected or not.
I've tried several methods including the findWindowPane() method and the activeWindow object, but none of them worked. (I didn't know all the parameters for findWindowPane() and the activeWindow doesn't have any info about specific tool window data)
Update
So I've checked the solution on this page: Show item history windows with TFS SDK
Unfortunately, when I'm trying to get the type of the history window, the result is null.
Type _dialogHistoryType;
Assembly tfsAssembly = typeof(Microsoft.TeamFoundation.VersionControl.Controls.LocalPathLinkBox).Assembly;
_dialogHistoryType = tfsAssembly.GetType("Microsoft.TeamFoundation.VersionControl.Controls.DialogHistory");
var historyWindow = package.FindToolWindow(_dialogHistoryType, 0, false);
My main goal is to get the selected history item's id from the history window during runtime.
Any suggestion, how to get the type?

How Outlook shows the PaperClip icon for any attachment other than embedded images?

For my use case, I need to find out if a mail item in outlook has any embedded image as an attachment. I am working on Outlook 2013+ version. It is my understanding that for all other embedded attachments, they can only be added in Rich Text format and Outlook marks them as attachment (Marked as PaperClip icon). But if the mail contains only a embedded image in HTML format then the PaperClip icon does not appear. Please feel free me to point me if I am wrong with this observation.
My question however is, how is outlook itself deciding and showing the paperclip icon? I used Outlook Spy but the PR_HasAttach is set to true for these mails. I have also read other solutions where people have pointed out that you can try to find tag in the HTML Mail body which mostly works. But has any body ever wondered about the PaperClip icon?
I am having this doubt because when I apply the DASL filter urn:schemas:httpmail:hasattachment = true, such mails are filtered out by the query. Same thing happens if you use has attachments filter in outlook itself. But if I select the same mail item, and try to explore this property either by code or by Outlook Spy, it comes as true. That is why I am thinking that it might have to do with the icon Or atleast If I can find the property which sets the icon.
Edit 1:
When I use the following code it does not work for embedded or hidden attachments. For others it works.
IEnumerator eNum = listOfSearchedOutlookItems.GetEnumerator();
while (eNum.MoveNext())
{
Outlook.MailItem mailItem;
try
{
mailItem = (Outlook.MailItem)eNum.Current;
bool b = mailItem.PropertyAccessor.GetProperty(#"http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B");
}
catch
{
continue;
}
}
However strangely the following works for all the cases (As many as I have tested). So in a way this problem is solved thanks to Dmitry's answer. But still wondering why is the previous one not working.
Outlook.Table table = MyFolder.GetTable(SomeFilterIfNeeded);
table.Columns.RemoveAll();
table.Columns.Add(#"http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B");
while (!table.EndOfTable)
{
Outlook.Row nextRow = table.GetNextRow();
bool b = (bool)nextRow[#"http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B"];
}
To hide the paperclip icon, Outlook sets SmartNoAttach named MAPI property (DASL name http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B).

How to configure auto update of view/form/dashboard on entity change via CRM SDK

Currently, we have the following situation:
Account entity contains online_status field, which can have either offline or online value. And we have an entity view, which shows only online accounts.
case1:
I open the view. It's empty for now;
I open an account form in another window and manually change online status from offline to online;
After clicking save, grid in view auto updates and starts showing this account
case2:
I change online status using SDK:
using (var proxy = CreateCrmProxy(broker))
{
proxy.EnableProxyTypes();
var crmAccount = proxy.Retrieve(Account.EntityLogicalName, aggregateId, new ColumnSet()) as Account;
crmAccount.OnlineStatus = //new online status;
proxy.Update(crmAccount);
}
CreateCrmProxy method creates an instance of OrganizationServiceProxy class.
In this case, online_status field updates successfully, but grid in view stays in an old state and I need to press "refresh" button in order to see valid information.
Is it possible to fire view auto update, using the technique from case2?
Thanks in advance!
No, you cant do this with a plugin, since plugin is purely backend and sub-grids are a front-end UI construct. Its possible you could do something hacky with calling a RetrieveMultiple after you make the update, but there wouldn't be any way to force the view to update itself.
A better option in your circumstance would be to trigger the change via javascript (a REST or SOAP Call would suffice), so that once the update is complete, then you can call a control.refresh. It would get a bit trickier on a dashboard because you wouldn't have a form to load the javascript with and the view would be in a different pane, but you could do something with a web resource and use the parent context.

Form Regions for Outlook and VSTO remove WebViewPane

I have just purchased: http://www.add-in-express.com/outlook-regions/
The reason why I have purchased that product is because I need to show a custom form on the main view of outlook when a specific folder is selected. I have managed to do so by doing the following:
Create a new Project int visual studio of type (Outlook 2010 Add-in)
Once that project is created I add:
Because I want that form to show on the main folder view of mail (replace all other views) I select this option:
I click next and follow all the defaults in order to create the form.
Once that form is created I add the buttons and images I need. In this example I will just add a button.
when I then run outlook and select my inbox folder this is what shows up:
(In other words every time I select a folder of type olMailItem that form shows up)
So now I solve my goal to display my custom form on the "main view of outlook"
Now my question is how can I show that form only on specific folders. For example I do not want to show that form when the folder "Inbox" is selected but I do want to show it when the folder "Outbox" is selected for example
Let's try to hide the form and show the default view when the button is clicked.
In order to solve that problem I have looked at: http://www.add-in-express.com/forum/read.php?FID=5&TID=4540
I have done the same steps but the form shows up again! In other words the code behind of the button looks like:
private void button1_Click(object sender, EventArgs e)
{
// get current folder in this case its inbox the one that is selected
MAPIFolder currentFolder = Globals.ThisAddIn.Application.ActiveExplorer().CurrentFolder;
Globals.ThisAddIn.ADXOlForm1Item.FolderName = string.Empty;
// clear web properties DO NOT SHOW WEB VIEW
currentFolder.WebViewURL = string.Empty;
currentFolder.WebViewOn = false;
// RESET FOLDER BY SELECTING A DIFFERENT ONE THEN THE SAME ONE
NameSpace nameSpace = Globals.ThisAddIn.Application.GetNamespace("MAPI");
MAPIFolder outboxFolder = nameSpace.GetDefaultFolder(OlDefaultFolders.olFolderOutbox);
Globals.ThisAddIn.Application.ActiveExplorer().CurrentFolder = outboxFolder; // CHANGE FOLDER TO A DIFFERNT ONE
System.Windows.Forms.Application.DoEvents();
Globals.ThisAddIn.Application.ActiveExplorer().CurrentFolder = currentFolder; // SET INBOX AGAIN
}
when I run that code the default view shows up for 1 second then it get's replaced with the form!
-------------------------------------------Edit-------------------------------------------
When I add the form region Addin Express adds a ADXOlFormsManager and a ADXOlFormsCollectionItem for the form that I created. Based on your answer I have done:
#region ADXOlForm1
// TODO: Use the ADXOlForm1Item properties to configure the region's location, appearance and behavior.
// See the "The UI Mechanics" chapter of the Add-in Express Developer's Guide for more information.
ADXOlForm1Item = new ADXOlFormsCollectionItem();
ADXOlForm1Item.FolderName = "MyCustomFolder"; // <---- ADDED THIS LINE HOPING TO SHOW THIS FORM ONLY WHEN THAT FOLDER IS SELECTED
ADXOlForm1Item.ExplorerLayout = ADXOlExplorerLayout.WebViewPane;
ADXOlForm1Item.ExplorerItemTypes = ADXOlExplorerItemTypes.olMailItem;
ADXOlForm1Item.UseOfficeThemeForBackground = true;
ADXOlForm1Item.FormClassName = typeof(ADXOlForm1).FullName;
this.FormsManager.Items.Add(ADXOlForm1Item);
#endregion
I was hoping for that form to only show up in MyCustomFolder but it does shows up when selecting any folder of type ADXOlExplorerItemTypes.olMailItem. Perhaps I am doing something wrong....
In other words I was hoping for only the MAPIFolder MyCustomFolder folder had the properties
WebViewOn=true;
WebViewURL = "...AppData\Local\Temp\AddinExpress\ADXOlFormGeneral.html"
but as I traverse all the folders in outlook I can see that all of them have those properties even after specifying ADXOlForm1Item.FolderName = "MyCustomFolder";
Thank you for choosing Add-in Express Regions.
I understand the "main view of outlook" as the folder that Outlook shows when it is started. By default, that folder is the top-level folder of the message store. Note that this can be changed, see File | Options | Advanced | Start Outlook in this folder. I use this setting so that my Outlook shows me the Inbox at start-up.
The below is a citation from the section Context-Sensitivity of Your Outlook Form, see see the PDF file in the folder {Add-in Express}\Docs\ on your development PC:
ADXOlFormsCollectionItem provides a number of properties that allow specifying the context settings for your form. Say, you can specify item types for which your form will be shown. Note that in case of explorer, the item types that you specify are compared with the default item type of the current folder. In addition, you can specify the names of the folders for which your form will be shown in the FolderName and FolderNames properties; these properties also work for Inspector windows – in this case, the parent folder of the Outlook item is checked. An example of the folder path is "\Personal Folders\Inbox".
A special value in FolderName is an asterisk ('*'), which means "all folders". You can also specify message class(es) for which your form will be shown. Note that all context-sensitivity properties of an ADXOlFormsCollectionItem are processed using the OR Boolean operation. That is, specifying e.g. folder names extends, but not limits, the list of contexts for which your form will be shown.
That is, if you need to show the form for a given folder, specify the path to that folder in the FolderName/*FolderNames* property.
Regards from Belarus (GMT+3),
Andrei Smolin, Add-in Express Team Leader

Categories