代码之家  ›  专栏  ›  技术社区  ›  Michael Shimmins

文件夹。绑定-“Id格式不正确”-Exchange Web服务托管API

  •  8
  • Michael Shimmins  · 技术社区  · 16 年前

    Folder.Id.UniqueId 从中检索到的文件夹的属性 FindFolders 通过查询字符串查询到另一页。在第二页我想用这个 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));
    

    同样的问题。

    有人知道如何绑定到具有给定唯一id的文件夹吗?

    3 回复  |  直到 12 年前
        1
  •  7
  •   Christian Sparre    15 年前

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

    结果发现,一些ID中有一个+符号,解码时会产生一个“”空白。简单地替换“+”就可以了。

    可能是问题所在。

    我知道这个问题很久以前就有人问过了,但这可能对将来的其他人有所帮助。

        2
  •  0
  •   Dylan    16 年前

        3
  •  -1
  •   Darin Dimitrov    16 年前

    您需要确保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>
    
    推荐文章