7

我将通过查询字符串从FindFolders查询中检索到的文件夹的Folder.Id.UniqueId属性传递给另一个页面。在这第二页我想使用UniqueId绑定到该文件夹​​列出其邮件:Folder.Bind - “Id is malformed” - Exchange Web Services托管API

string parentFolderId = Request.QueryString["id"]; 
... 
Folder parentFolder = Folder.Bind(exchangeService, parentFolderId); 
// do something with parent folder 

当我运行这段代码,它抛出一个异常,告诉我该标识的格式不正确。我想也许它需要包装在FolderId对象中:

Folder parentFolder = Folder.Bind(exchangeService, new FolderId(parentFolderId)); 

同样的问题。

我一直在寻找一段时间,并且发现了一些关于Base64/UTF8转换的建议,但是又一次没有解决问题。

任何人都知道如何绑定到具有给定唯一ID的文件夹?

回答

0

是否正确地形成了parentFolderId值,或者当您尝试实例化文件夹对象时,它是否会引起抖动?您是否在将id作为查询字符串传递之前执行了HttpUtility.UrlEncode(不要忘记之后再执行HttpUtility.UrlDecode)

0

您需要确保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("[email protected]"); 

     // 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> 
7

我有一个类似的问题和使用进行urlencode/urldecode以确保IDS是格式正确。但是其中一个用户有消息会导致错误。

事实证明,某些ID在其中有一个+符号,导致解码时出现空格。 “'+'的简单替换取得了诀窍。

可能是问题所在。

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

相关问题