英文:
How to work with single-value extended properties?
问题
在我们的应用程序中,我们希望将投票选项与MS Graph集成。不幸的是,官方尚未提供此功能,因此我们必须创建自己的解决方案。我找到了这个链接:https://learn.microsoft.com/en-us/answers/questions/826338/adding-voting-option-in-microsoft-graph-api
现在的问题是,我如何在C#中处理单值属性?是否有任何用于处理的类,也许是SingleValueLegacyExtendedProperty
?
英文:
I have searched everywhere for an instruction, how to work with single-value extended properties, but have not found something like that.
In our application, we want to integrate voting options with MS Graph. Unfortunately, it is not official available yet, so we have to create our own solution. I found this one: https://learn.microsoft.com/en-us/answers/questions/826338/adding-voting-option-in-microsoft-graph-api
Now the question is, how I can work with single-value properties in C#. Are there any classes to work with, maybe SingleValueLegacyExtendedProperty
?
答案1
得分: 0
在SDK v5中,在读取单值扩展属性时,您需要在扩展查询参数中指定属性:
var result = await _client.Me.Messages.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Expand = new string[] { "singleValueExtendedProperties($filter=id+eq+'Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520')" };
});
// 获取具有单值扩展属性的第一条消息
var message = result.Value.FirstOrDefault(x => x.SingleValueExtendedProperties != null);
var votingData = message.SingleValueExtendedProperties[0].Value;
要创建具有单值扩展属性的新消息:
var body = new SendMailPostRequestBody
{
Message = new Message
{
Subject = "Voting",
Sender = new Recipient
{
EmailAddress = new EmailAddress
{
Address = "xxx@contoso.com"
}
},
ToRecipients = new List<Recipient>
{
new Recipient
{
EmailAddress = new EmailAddress { Address = "yyy@contoso.com" }
}
},
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Please vote"
},
SingleValueExtendedProperties = new List<SingleValueLegacyExtendedProperty>
{
new SingleValueLegacyExtendedProperty
{
Id = "Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520",
Value = "data"
}
}
},
SaveToSentItems = true
};
await _client.Me.SendMail.PostAsync(body);
对于较旧版本的SDK,如v4和v3:
var response = await client.Me.Messages.Request()
.Expand("singleValueExtendedProperties($filter=id+eq+'Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520')")
.GetAsync();
var message = response.FirstOrDefault(x => x.SingleValueExtendedProperties != null);
var votingData = message.SingleValueExtendedProperties[0].Value;
新消息:
var message = new Message
{
Subject = "Voting",
Sender = new Recipient
{
EmailAddress = new EmailAddress
{
Address = "xxx@contoso.com"
}
},
ToRecipients = new List<Recipient>
{
new Recipient
{
EmailAddress = new EmailAddress { Address = "yyy@contoso.com" }
}
},
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Please vote"
},
SingleValueExtendedProperties = new MessageSingleValueExtendedPropertiesCollectionPage
{
new SingleValueLegacyExtendedProperty
{
Id = "Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520",
Value = "data"
}
}
};
await client.Me.SendMail(message, true).Request().PostAsync();
英文:
In SDK v5, when reading single-value extended property, you have to specify the property in expand query parameter:
var result = await _client.Me.Messages.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Expand = new string[] { "singleValueExtendedProperties($filter=id+eq+'Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520')" };
});
// get first message with single-value extended property
var message = result.Value.FirstOrDefault(x => x.SingleValueExtendedProperties != null);
var votingData = message.SingleValueExtendedProperties[0].Value;
To create a new message with single-value extended property
var body = new SendMailPostRequestBody
{
Message = new Message
{
Subject = "Voting",
Sender = new Recipient
{
EmailAddress = new EmailAddress
{
Address = "xxx@contoso.com"
}
},
ToRecipients = new List<Recipient>
{
new Recipient
{
EmailAddress = new EmailAddress { Address = "yyy@contoso.com" }
}
},
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Please vote"
},
SingleValueExtendedProperties = new List<SingleValueLegacyExtendedProperty>
{
new SingleValueLegacyExtendedProperty
{
Id = "Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520",
Value = "data"
}
}
},
SaveToSentItems = true
};
await _client.Me.SendMail.PostAsync(body);
For older version of SDK like v4 and v3
var response = await client.Me.Messages.Request()
.Expand("singleValueExtendedProperties($filter=id+eq+'Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520')")
.GetAsync();
var message = response.FirstOrDefault(x => x.SingleValueExtendedProperties != null);
var votingData = message.SingleValueExtendedProperties[0].Value;
New message
var message = new Message
{
Subject = "Voting",
Sender = new Recipient
{
EmailAddress = new EmailAddress
{
Address = "xxx@contoso.com"
}
},
ToRecipients = new List<Recipient>
{
new Recipient
{
EmailAddress = new EmailAddress { Address = "yyy@contoso.com" }
}
},
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Please vote"
},
SingleValueExtendedProperties = new MessageSingleValueExtendedPropertiesCollectionPage
{
new SingleValueLegacyExtendedProperty
{
Id = "Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520",
Value = "data"
}
}
};
await client.Me.SendMail(message, true).Request().PostAsync();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论