[英]Folder.Bind - “Id is malformed” - Exchange Web Services Managed API
I'm passing the Folder.Id.UniqueId
property of a folder retrieved from a FindFolders
query via the query string to another page. 我将通过查询字符串从
FindFolders
查询检索到的文件夹的Folder.Id.UniqueId
属性传递给另一个页面。 On this second page I want to use that UniqueId
to bind to the folder to list its mail items: 在第二页上,我想使用
UniqueId
绑定到文件夹以列出其邮件项:
string parentFolderId = Request.QueryString["id"];
...
Folder parentFolder = Folder.Bind(exchangeService, parentFolderId);
// do something with parent folder
When I run this code it throws an exception telling me the Id is malformed. 当我运行此代码时,它会抛出异常,告诉我Id是格式错误的。 I thought maybe it needs to be wrapped in a
FolderId
object: 我想也许它需要包装在
FolderId
对象中:
Folder parentFolder = Folder.Bind(exchangeService, new FolderId(parentFolderId));
Same issue. 同样的问题。
I've been searching for a while, and have found some suggestions about Base64/UTF8 conversion, but again that did not solve the problem. 我已经搜索了一段时间,并找到了一些关于Base64 / UTF8转换的建议,但同样没有解决问题。
Anyone know how to bind to a folder with a given unique id? 任何人都知道如何绑定到具有给定唯一ID的文件夹?
I had a similar problem and used urlencode/urldecode to make sure the ids was properly formatted. 我有类似的问题,并使用urlencode / urldecode来确保id格式正确。 However one of the users had messages that would result in errors.
但是,其中一个用户的消息会导致错误。
It turned out that some of the ids had a + sign in them resulting in a ' ' blank space when decoded. 事实证明,有些ID在其中有+符号,因此在解码时会产生“空白”。 A simple replace of ' ' the '+' did the trick.
简单地替换''''+'就可以了。
Could be the problem. 可能是问题。
I know the question was asked a long time ago, but this might be helpful to others in the future. 我知道很久以前就问过这个问题,但这可能会对将来的其他人有所帮助。
Is the parentFolderId value correctly formed, or is it just throwing a wobbly when you try and instantiate the folder object? parentFolderId值是否正确形成,或者当您尝试实例化文件夹对象时它是否只是摇摆不定? Are you doind a HttpUtility.UrlEncode on the id before you pass it as a query string (don't forget to do an HttpUtility.UrlDecode afterwards)
在将它作为查询字符串传递之前,您是否在id上执行了HttpUtility.UrlEncode(之后不要忘记执行HttpUtility.UrlDecode)
You need to make sure that the id is properly encoded. 您需要确保id已正确编码。 Here's an example.
这是一个例子。
Model: 模型:
public class FolderViewModel
{
public string Id { get; set; }
}
Controller: 控制器:
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();
}
}
And the Index 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.