User User
Guest
|
Hi,
How can I add new columns at the view in inbox folder, type Yes/No, at Outlook 2003 and assigned the values for they to each mail item. |
|
User User
Guest
|
can change You example outlookview-cs at the new column added,to each email write an property type of Yes / No, please? |
|
Andrei Smolin
Add-in Express team
Posts: 18829
Joined: 2006-05-11
|
Hi User (can't remember if you ever mentioned your name),
See the item.UserProperties.Add method. It adds the property as a custom field to the folder that the item is in. To add the custom field to the view, you need to use the View.XML property, see Outlook Help.
Andrei Smolin
Add-in Express Team Leader |
|
User User
Guest
|
I already did that, but in the view i don?t watch the property assigned to the mail items
thanks for the replay |
|
User User
Guest
|
Hi have this code:
private void CreateViewVersion03()
{
string[] myColumns = new string[] { "Column1" , "Column2", "Column3" };
uint[] myColumnsUint = new uint[] { 0x6801000B, 0x6802000B, 0x6803000B };
Outlook.NameSpace olNs = OutlookApp.GetNamespace("MAPI");
Outlook.MAPIFolder inboxFolder = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
AddinExpress.MAPI.ADXMAPIStoreAccessor mapi = new ADXMAPIStoreAccessor();
mapi.Initialize(false);
object missing = Type.Missing;
mapi.SetProperty(inboxFolder, 0x6801000B, missing);
mapi.SetProperty(inboxFolder, 0x6802000B, missing);
mapi.SetProperty(inboxFolder, 0x6803000B, missing);
mapi.LogOff();
mapi.Dispose();
bool viewExists = false;
Microsoft.Office.Interop.Outlook.View view = null;
Microsoft.Office.Interop.Outlook.Views views = null;
Microsoft.Office.Interop.Outlook.NameSpace ns = null;
Microsoft.Office.Interop.Outlook.MAPIFolder folder = null;
try
{
ns = (Microsoft.Office.Interop.Outlook.NameSpace)OutlookApp.GetNamespace("MAPI");
folder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
views = inboxFolder.Views;
for (int i = 1; i < views.Count; i++)
{
view = null;
try
{
view = views[i];
if (view.Name == "NEW VIEW")
{
viewExists = true;
break;
}
}
finally
{
if (view != null)
Marshal.ReleaseComObject(view);
}
}
if (!viewExists)
{
string xmlString = String.Empty, xmlColumns = String.Empty;
view = views.Add("NEW VIEW",
Microsoft.Office.Interop.Outlook.OlViewType.olTableView,
Microsoft.Office.Interop.Outlook.OlViewSaveOption.olViewSaveOptionThisFolderEveryone);
xmlString = view.XML;
int pos = xmlString.IndexOf("<orderby>");
if (pos >= 0)
{
for (int c = 0; c < myColumns.Length; c++)
{
xmlColumns += "\r\n\t" + @"<column>";
xmlColumns += "\r\n\t\t" + @"<fo rmat>boolicon</format>";
xmlColumns += "\r\n\t\t" + @"<heading>" + myColumns[c] + "</heading>";
xmlColumns += "\r\n\t\t" + @"<prop>http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/" + myColumnsUint[c] + "</prop>";
xmlColumns += "\r\n\t\t" + @"<type>boolean</type>";
xmlColumns += "\r\n\t\t" + @"<width>50</width>";
xmlColumns += "\r\n\t\t" + @"<st yle>padding-left:3px;;text-align:center</style>";
xmlColumns += "\r\n\t\t" + @"<editable>1</editable>";
xmlColumns += "\r\n\t\t" + @"<displayformat>3</displayformat>";
xmlColumns += "\r\n\t" + @"</column>";
}
if (xmlColumns != String.Empty)
{
xmlColumns += "\r\n\t";
xmlString = xmlString.Ins ert(pos, xmlColumns);
}
view.XML = xmlString;
view.Save();
try
{
try
{
X view.Apply();
}
catch (Exception ex)
{
}
AddUserPropertyValuesToItems2003();
}
catch (Exception ex)
{
}
}
}
else
{
if (folder.CurrentView.Name != "NEW VIEW")
{
try
{
OutlookApp.ActiveExplorer().CurrentView = folder.Views[ReturnIndexView("NEW VIEW")];
}
catch (Exception ex)
{
}
}
}
}
finally
{
if (views != null)
Marshal.ReleaseComObject(views);
if (folder != null)
Marshal.ReleaseComObject(folder);
if (ns != null)
Marshal.ReleaseComObject(ns);
}
}
private void AddUserPropertyValuesToItems2003()
{
// Create user property on all mails
Outlook.NameSpace olNs = OutlookApp.GetNamespace("MAPI");
Outlook.MAPIFolder theFolder = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Microsoft.Office.Interop.Outlook.Items items = theFolder.Items;
Microsoft.Office.Interop.Outlook.MailItem theMail = null;
for (int i = 1; i <= items.Count; i++)
{
try
{
if (items[i] is Microsoft.Office.Interop.Outlook.MailItem)
{
try
{
theMail = (Microsoft.Office.Interop.Outlook.MailItem)items[i];
Outlook.UserProperty prop1 = theMail.UserProperties.Add("prop1", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, true, Type.Missing);
prop1.Value = true;
Outlook.UserProperty prop2 = theMail.UserProperties.Add("prop2", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, true, Type.Missing);
prop2.Value = true;
Outlook.UserProperty prop3 = theMail.UserProperties.Add("prop3", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, true, Type.Missing);
prop3.Value = true;
theMail.Save();
X AddinExpress.MAPI.ADXMAPIStoreAccessor mapi = new ADXMAPIStoreAccessor();
X mapi.Initialize(false);
X object val ue = true;
X mapi.SetProperty(theMail, 0x6801000B, true);
X mapi.SetProperty(theMail, 0x6802000B, true);
X mapi.SetProperty(theMail, 0x6803000B, true);
theMail.Save();
}catch(System.Exception ex)
{
MessageBox.Show("Add prop" + ex.Message);
}
//mapi.LogOff();
//mapi.Dispose();
if (prop1 != null) Marshal.ReleaseComObject(prop1);
if (prop2 != null) Marshal.ReleaseComObject(prop2);
if (prop3 != null) Marshal.ReleaseComObject(prop3);
}
}
catch (System.Exception ex)
{
}
finally
{
if (theMail != null) Marshal.ReleaseComObject(theMail);
}
}
if (items != null) Marshal.ReleaseComObject(items);
if (theFolder != null) Marshal.ReleaseComObject(theFolder);
GC.Collect();
}
public int ReturnIndexView(string vista)
{
Outlook.NameSpace olNs = OutlookApp.GetNamespace("MAPI");
Outlook.MAPIFolder inboxFolder = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
for (int i = 1; i <= inboxFolder.Views.Count; i++)
{
if (inboxFolder.Views[i].Name == vista)
{
return IndexNovaVista = i;
}
}
if (inboxFolder != null) Marshal.ReleaseComObject(inboxFolder);
return -1;
}
private void adxOutlookEvents_Startup(object sender, EventArgs e)
{
CreateViewVersion03();
}
I don't see nothing in the new view, at the 3 new colums created. Can help me? |
|
Andrei Smolin
Add-in Express team
Posts: 18829
Joined: 2006-05-11
|
|