简体   繁体   English

Folder.Bind - “Id格式错误” - Exchange Web服务托管API

[英]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.

相关问题 如何使用 C# 和 Exchange Web Services Managed API 获取文件夹的策略? - How to get a folder's policy using C# and Exchange Web Services Managed API? 如何使用Exchange Web Services 2010托管API获取文件夹大小? - How do I get folder size with Exchange Web Services 2010 Managed API? Folder.Bind引发ArgumentNullException - Folder.Bind Throws ArgumentNullException 异步Folder.Bind上的ArgumentException - ArgumentException on async Folder.Bind Exchange Web服务托管API:访问其他用户项 - Exchange Web Services Managed API: Accessing other users items 如何在托管的Exchange Web服务中更改AppointmentStatus - How to change AppointmentStatus in managed Exchange Web Services EWS托管API 2.0 ID格式错误 - EWS Managed API 2.0 Id is malformed C# 交换 Web 服务托管 API 模拟 -&gt; Microsoft Graph ZDB974238714CA8DE634A7CE108A14F - C# Exchange Web Services Managed API Impersonation -> Microsoft Graph API 如何使用Exchange Web服务托管API列出这些文件夹中的所有文件夹和文件? - How to list all folders and files in those folders using Exchange Web Services Managed API? 从Exchange Web服务托管API获取收件箱中的所有邮件,并将其存储为.eml文件 - Fetching all mails in Inbox from Exchange Web Services Managed API and storing them as a .eml files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM