Exemplo n.º 1
0
        private uint CreateMsgWithAttachement(out byte[] entryId)
        {
            ASCIIEncoding asciiencoding = new ASCIIEncoding();
            uint          @int;

            using (MapiMessage mapiMessage = this.testFolder.CreateMessage())
            {
                PropValue[] props = new PropValue[]
                {
                    new PropValue(PropTag.Subject, string.Format("CITestSearch: {0}.", this.searchString)),
                    new PropValue(PropTag.Body, string.Format("The unique search string in the body is: {0}.", this.searchString)),
                    new PropValue(PropTag.MessageDeliveryTime, (DateTime)ExDateTime.Now)
                };
                this.threadExit.CheckStop();
                mapiMessage.SetProps(props);
                int num;
                using (MapiAttach mapiAttach = mapiMessage.CreateAttach(out num))
                {
                    string s     = string.Format("This is a test msg created by test-search task (MSExchangeSearch {0}).It will be deleted soon...", this.searchString);
                    byte[] bytes = asciiencoding.GetBytes(s);
                    using (MapiStream mapiStream = mapiAttach.OpenStream(PropTag.AttachDataBin, OpenPropertyFlags.Create))
                    {
                        mapiStream.Write(bytes, 0, bytes.Length);
                        mapiStream.Flush();
                        this.threadExit.CheckStop();
                    }
                    props = new PropValue[]
                    {
                        new PropValue(PropTag.AttachFileName, "CITestSearch.txt"),
                        new PropValue(PropTag.AttachMethod, AttachMethods.ByValue)
                    };
                    mapiAttach.SetProps(props);
                    mapiAttach.SaveChanges();
                }
                this.threadExit.CheckStop();
                mapiMessage.SaveChanges();
                entryId = mapiMessage.GetProp(PropTag.EntryId).GetBytes();
                @int    = (uint)mapiMessage.GetProp(PropTag.DocumentId).GetInt();
            }
            return(@int);
        }