![](/img/trans.png)
[英]How to get a folder's policy using C# and Exchange Web Services Managed API?
[英]Folder.Bind - “Id is malformed” - Exchange Web Services Managed API
我将通过查询字符串从FindFolders
查询检索到的文件夹的Folder.Id.UniqueId
属性传递给另一个页面。 在第二页上,我想使用UniqueId
绑定到文件夹以列出其邮件项:
string parentFolderId = Request.QueryString["id"];
...
Folder parentFolder = Folder.Bind(exchangeService, parentFolderId);
// do something with parent folder
当我运行此代码时,它会抛出异常,告诉我Id是格式错误的。 我想也许它需要包装在FolderId
对象中:
Folder parentFolder = Folder.Bind(exchangeService, new FolderId(parentFolderId));
同样的问题。
我已经搜索了一段时间,并找到了一些关于Base64 / UTF8转换的建议,但同样没有解决问题。
任何人都知道如何绑定到具有给定唯一ID的文件夹?
我有类似的问题,并使用urlencode / urldecode来确保id格式正确。 但是,其中一个用户的消息会导致错误。
事实证明,有些ID在其中有+符号,因此在解码时会产生“空白”。 简单地替换''''+'就可以了。
可能是问题。
我知道很久以前就问过这个问题,但这可能会对将来的其他人有所帮助。
parentFolderId值是否正确形成,或者当您尝试实例化文件夹对象时它是否只是摇摆不定? 在将它作为查询字符串传递之前,您是否在id上执行了HttpUtility.UrlEncode(之后不要忘记执行HttpUtility.UrlDecode)
您需要确保id已正确编码。 这是一个例子。
模型:
public class FolderViewModel
{
public string Id { get; set; }
}
控制器:
public class HomeController : Controller
{
public ActionResult Index()
{
ExchangeService service = new ExchangeService();
service.Credentials = new NetworkCredential("username", "pwd", "domain");
service.AutodiscoverUrl("foo@company.com");
// Get all folders in the Inbox
IEnumerable<FolderViewModel> model = service
.FindFolders(WellKnownFolderName.Inbox, new FolderView(int.MaxValue))
.Select(folder => new FolderViewModel { Id = folder.Id.UniqueId });
return View(model);
}
public ActionResult Bind(string id)
{
Folder folder = Folder.Bind(service, new FolderId(id));
// TODO: Do something with the selected folder
return View();
}
}
和索引视图:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<SomeNs.Models.FolderViewModel>>" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% foreach (var folder in Model) { %>
<%: Html.ActionLink(Model.Id, "Bind", new { id = Model.Id }) %>
<% } %>
</asp:Content>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.