【问题标题】:Folder.Bind - "Id is malformed" - Exchange Web Services Managed APIFolder.Bind - “Id 格式错误” - Exchange Web 服务托管 API
【发布时间】:2011-02-01 12:57:47
【问题描述】:

我通过查询字符串将从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 的文件夹吗?

【问题讨论】:

    标签: c# .net exchange-server exchangewebservices ews-managed-api


    【解决方案1】:

    我遇到了类似的问题,并使用了 urlencode/urldecode 来确保 id 的格式正确。然而,其中一位用户的消息会导致错误。

    事实证明,一些 id 中有一个 + 号,导致解码时出现“”空白。一个简单的 ' ' 替换 '+' 就可以了。

    可能是问题所在。

    我知道这个问题是很久以前提出的,但这可能对其以后的其他人有所帮助。

    【讨论】:

      【解决方案2】:

      parentFolderId 值的格式是否正确,或者当您尝试实例化文件夹对象时它只是在晃动?在将 id 作为查询字符串传递之前,您是否在 id 上执行了 HttpUtility.UrlEncode(不要忘记之后执行 HttpUtility.UrlDecode)

      【讨论】:

        【解决方案3】:

        您需要确保 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>
        

        【讨论】:

          猜你喜欢
          • 2011-06-12
          • 2020-09-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-03-02
          • 2011-04-16
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多