I'm working on an Outlook 2013 plugin that needs to access the emails currently displayed in the email list pane.
I already searched around a lot but I could only find ways to list emails within the current selected folder:
Outlook.MAPIFolder curFolder = this.Application.ActiveExplorer().CurrentFolder;
Outlook.Items mailItems = curFolder.Items;
MailItem item = mailItems.GetFirst();
This would work fine if the user didn't apply any search filters; but if a filter is applied via the instant search bar this code would produce the same list of MailItems as if the filter wasn't applied.
I thought of two ways of potentially solving this but couldn't find any resources online that worked for either.
1) Preferably, get direct read access to the MailItem list currently rendered within the email list pane.
2) Alternatively, read the value in the instant search text-box and apply that to the currently selected folder using the Items.Find() command.
Any guidance or explanations would be greatly appreciated; thanks in advance.
The Outlook object model doesn't provide any direct access to the filter line or items shown in Outlook.
But the Explorer class provides the CurrentView property which returns an object representing the current view. The View class provides the Filter property which is applied to the current view.
Sub ResetView()
Dim v as Outlook.View
' Save a reference to the current view object
Set v = Application.ActiveExplorer.CurrentView
' v.Filter
End Sub
So, you can apply the filter to the Items collection and get the same set of items.
Related
I want a selected attachments from below window.
I have used Explorer.AttachmentSelection method. But its not giving me any selection.
How to achieve it?
The AttachmentSelection object contains a read-only collection of attachments that are selected in an item that is in the active inspector or the active explorer. Use the ActiveExplorer method of the Application class which returns the topmost Explorer object on the desktop. An Explorer that represents the topmost explorer on the desktop is returned. You may get Nothing or Null if no explorer is active. So, you may get null if no attachments is selected in the view.
I'd suggest click on any attachment in the view and validate how the code is working. You should get the attachment instance selected in the Outlook view.
You actually need to select an attachment in the preview pane (so that "Back to message" button becomes visible) for Explorer.AttachmentSelection collection to contain anything.
I am developing an Outlook Addin in which I am adding a category to a mail. In order add the category I am adding it first by clicking VIEW tab and then clicking on Add Column and then clicking on Categories, adding the "Categories" then pressing OK. Now I want to do this programmatically. Is that possible?
Yes, it is. You need to customize the current view of the explorer or folder if you want to apply changes for every explorer window. To obtain a View object for the view of the current Explorer , use Explorer.CurrentView instead of the CurrentView property of the current Folder object returned by Explorer.CurrentFolder. You must save a reference to the View object returned by CurrentView before you proceed to use it for any purpose.
The View object allows you to create customizable views that allow you to better sort, group and ultimately view data of all different types. There are a variety of different view types that provide the flexibility needed to create and maintain your important data.
The table view type ( olTableView ) allows you to view data in a simple field-based table.
The Calendar view type ( olCalendarView ) allows you to view data in a calendar format.
The card view type ( olCardView ) allows you to view data in a series of cards. Each card displays the information contained by the item and can be sorted.
The icon view type ( olIconView ) allows you to view data as icons, similar to a Windows folder or explorer.
The timeline view type ( olTimelineView ) allows you to view data as it is received in a customizable linear time line.
Views are defined and customized using the View object's XML property. The XML property allows you to create and set a customized XML schema that defines the various features of a view.
The XML definition describes the view type by using a series of tags and keywords corresponding to various properties of the view itself. When the view is created, the XML definition is parsed to render the settings for the new view.
To determine how the XML should be structured when creating views, you can create a view by using the Outlook user interface and then you can retrieve the XML property for that view.
Sub DisplayViewDef()
'Displays the XML definition of a View object
Dim objName As Outlook.NameSpace
Dim objViews As Outlook.Views
Dim objView As Outlook.View
Set objName = Application.GetNamespace("MAPI")
Set objViews = objName.GetDefaultFolder(olFolderInbox).Views
'Return a view called Table View if it already exists, else create one
Set objView = objViews.Item("Table View")
If objView Is Nothing Then
Set objView = objViews.Add("Table View", olTableView, olViewSaveOptionAllFoldersOfType)
End If
MsgBox objView.XML
End Sub
To programmatically add a custom field to a view, use the Add method of the ViewFields object. This is the recommended way to dynamically change the view over setting the XML property of the View object.
I am developing VSTO addin using C#.
Here, I have drag one file from my PC to outlook folder. It displays in outlook as show in picture.
Now I want to add one column in that folder.
I have done some code to add custom column in folder. It will display in picture. Column name is ABCDEFGHI.
I want to update the value of ABCD.pdf file property.
As per outlook ABCD.pdf is a DocumentItem. I want to add my custom property for that file, to display in view.
This is my sample code.
UserProperties objUserProperties = objItem.UserProperties;
UserProperty objUserProperty = objUserProperties.Add("ABCDEFGHI", OlUserPropertyType.olText);
objt.Value = "YYYY";
This will give me an error.
Error:
If you take a look at the UserProperties.Add method description in MSDN you can see the following description:
You cannot add custom properties to Office document items such as Word, Excel, or PowerPoint files. You will receive an error when you try to programmatically add a user-defined field to a DocumentItem object.
Instead, I'd recommend creating any Outlook item and attaching a document to it. Following that way you will be able to customize the View by adding user properties as you need.
working with SharePoint, on the info path form I have a group, which then has a sub group. There can then be any amount of attachment controls on this sub group.
When the form is submitted I am sending the attachments to be uploaded somewhere else. Issue is, when I submit the form, these attachments get sent every time regardless if they are new are not. I currently have the code to handle the uploads in the ItemUpdated(SPItemEventProperties properties) method. I've done some reading and I know I will have to change it so that I am making this call from the ItemUpdating method instead. But from there I am unsure what is the best way to check for only 'new' attachments to be sent.
Any suggestions? New to SharePoint development so I can try and clarify if some things don't make sense.
In general you will always receive all attachments within the EventReceiver. Now you have to check in your EventReceivers ItemUpdating Event which items are new. You have to check the AfterProperties (which you are sending by your form) and the properties.ListItem (BeforeProperties and AfterProperties in Sharepoint Event Receivers).
First i would load all attachment from the form (AfterProperties) to a collection and then the attachment from the item which already exist in the list which you are trying to update. These attachment of the currently existing item you also load to a collection. Then you can check through LINQ for example if the attachments from you form exist in the item or which do not and then add only the new ones!
Sorry if this belongs on SP SE, if so please migrate.
I aplogize in advanced if my terminonlogy is off this is all new to me. I have a Sharepoint I am helping maintain. The Sharepoint has custom code (WSP's) that make up Sharepoint Lists/List items on the Sharepoint, which are created via code (.net C#). From what I'm seeing, in addition to creating the forms for creating new list items and defining the list items, you also set the url for each list item action (namely, when you click the checkbox next to a list item, the ribbon bar has buttons for "view" and "edit" which in theory you're supposed to set to the form page url's for, such as ViewItem.aspx, EditItem.aspx, etc). I can create a different page for viewing the list item and a different page for editing the list item of my custom list, but the problem is that view list item is identitical to edit list item with the exception that in "view list item" all the fields are turned to disabled once they are populated.
It seems extremely redundant to create a copy page of all the exact same logic as the edit page, plus the few extra lines of code to disable the fields once they've been populated. Is there another way (such as somehow altering the querystring generated by Sharepoint so I can add my own flag to indicate that the user is "viewing" the form instead of editing it)? I was able to use the same page for edit and new form because when you edit a list item SP adds the list item "ID" to the querystring paramater, but i dont see a parameter I could key off of to indicate that the form should be opened in "view" mode.