質問

開発の見通し2007年に追加します。試験用の展望カテゴリ名を変更したいいくらいが丁度いい、以下のコードブロック

 var session = Application.Session;
 var categories = session.Categories;
 var category1 = session.Categories[1];

 //catefory1.Name is "Group1" before executing line below
 category1.Name = "TEST!!!";

 Marshal.ReleaseComObject(category1);
 Marshal.ReleaseComObject(categories);
 Marshal.ReleaseComObject(session);

末尾に追加 private void ThisAddIn_Startup(object sender, EventArgs e) 方法。カテゴリーに名称変更な展望を閉じると、上記のラインと、見通しを再開しました-カテゴリの名前が表に出ることはありません"試験!!!" としてできたので、良かったです。それが"Group1"としては以前の名前変更.可能で名前の変更の展望カテゴリ"永遠"によるコードについて教えてください。Microsoft.ます。Interop.きます。カテゴリにはSave()またはUpdate()や張()。

P.S.開発の見通し2007年の追加-利用Visual Studio2008年.純3.5、C#3.問題は、再現の見通し2007年SP1およびSP2.その他のバージョンの展望なかった。

役に立ちましたか?

解決

私はその問題が解ける問題自体にそうな見通し2007年のバグ)をhack.以下のリンクを教えてくれるのhack(マットが十分になされていないのが評判により1リンク):

ハッキング自体は下記の通りです:

using System;
using System.Text;
using System.Xml;
using System.IO;
using Microsoft.Office.Interop.Outlook;

namespace OutlookHack
{
    public static class OutlookCategoryHelper
    {
        private const string CategoryListStorageItemIdentifier = "IPM.Configuration.CategoryList";
        private const string CategoryListPropertySchemaName = @"http://schemas.microsoft.com/mapi/proptag/0x7C080102";
        private const string CategoriesXmlElementNamespace = "CategoryList.xsd";
        private const string XmlNamespaceAttribute = "xmlns";
        private const string CategoryElement = "category";
        private const string NameAttribute = "name";

        public static void RenameCategory(string oldName, string newName, Application outlookApplication)
        {
            MAPIFolder calendarFolder = outlookApplication.Session.GetDefaultFolder(
                OlDefaultFolders.olFolderCalendar);
            StorageItem categoryListStorageItem = calendarFolder.GetStorage(
                CategoryListStorageItemIdentifier, OlStorageIdentifierType.olIdentifyByMessageClass);

            if (categoryListStorageItem != null)
            {
                PropertyAccessor categoryListPropertyAccessor = categoryListStorageItem.PropertyAccessor;
                string schemaName = CategoryListPropertySchemaName;
                try
                {
                    // next statement raises Out of Memory error if property is too big
                    var xmlBytes = (byte[])categoryListPropertyAccessor.GetProperty(schemaName);

                    // the byte array has to be translated into a string and then the XML has to be parsed
                    var xmlReader = XmlReader.Create(new StringReader(Encoding.UTF8.GetString(xmlBytes)));

                    // xmlWriter will write new category list xml with renamed category
                    XmlWriterSettings settings = new XmlWriterSettings { Indent = true, IndentChars = ("\t") };
                    var stringWriter = new StringWriter();
                    var xmlWriter = XmlWriter.Create(stringWriter, settings);

                    xmlReader.Read(); // read xml declaration
                    xmlWriter.WriteNode(xmlReader, true);
                    xmlReader.Read(); // read categories
                    xmlWriter.WriteStartElement(xmlReader.Name, CategoriesXmlElementNamespace);
                    while (xmlReader.MoveToNextAttribute())
                    {
                        if (xmlReader.Name != XmlNamespaceAttribute) // skip namespace attr
                        {
                            xmlWriter.WriteAttributeString(xmlReader.Name, xmlReader.Value);
                        }
                    }
                    while (xmlReader.Read())
                    {
                        switch (xmlReader.NodeType)
                        {
                            case XmlNodeType.Element: // read category
                                xmlWriter.WriteStartElement(CategoryElement);
                                while (xmlReader.MoveToNextAttribute())
                                {
                                    if ((xmlReader.Name == NameAttribute) && (xmlReader.Value == oldName))
                                    {
                                        xmlWriter.WriteAttributeString(NameAttribute, newName);
                                    }
                                    else
                                    {
                                        xmlWriter.WriteAttributeString(xmlReader.Name, xmlReader.Value);
                                    }
                                }
                                xmlWriter.WriteEndElement();
                                break;
                            case XmlNodeType.EndElement: // categories ended
                                xmlWriter.WriteEndElement();
                                break;
                        }
                    }
                    xmlReader.Close();
                    xmlWriter.Close();

                    xmlBytes = Encoding.UTF8.GetBytes(stringWriter.ToString());
                    categoryListPropertyAccessor.SetProperty(schemaName, xmlBytes);
                    categoryListStorageItem.Save();
                }
                catch (OutOfMemoryException)
                {
                    // if error is "out of memory error" then the XML blob was too big
                }
            }
        }
    }
}

このヘルパーメソッドを呼び出す必要以前のカテゴリ名を変更したい。

 var session = Application.Session;
 var categories = session.Categories;
 var category1 = session.Categories[1];

 //catefory1.Name is "Group1" before executing line below
 OutlookCategoryHelper.RenameCategory(category1.Name, "TEST!!!", Application);
 category1.Name = "TEST!!!";

 Marshal.ReleaseComObject(category1);
 Marshal.ReleaseComObject(categories);
 Marshal.ReleaseComObject(session);

他のヒント

このは、Outlookのバグは、Outlook 2007 SP2で導入されている。

の「次のシナリオを検討してください。あなたがOutlook 2007で新しいカテゴリを作成するために実行可能なカスタムアプリケーションを持っています。 あなたがOutlook 2007を再起動する場合は、あなたが作成したカテゴリが予期せず削除され、その後、Outlook 2007で新しいカテゴリを作成するためのアプリケーションを実行します。この問題は、あなたがFebruarycumulative更新またはSP2をインストールした後に発生します。 "

2009年6月30日以来利用できる修正プログラムがあります: http://support.microsoft.com/default.aspx/kb/970944/アン

よろしく、 ティム

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top