Folder.Bind - "Id is malformed" - Exchange Web Services Managed API
Asked Answered
R

3

8

I'm passing the Folder.Id.UniqueId property of a folder retrieved from a FindFolders query via the query string to another page. On this second page I want to use that UniqueId to bind to the folder to list its mail items:

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. I thought maybe it needs to be wrapped in a FolderId object:

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.

Anyone know how to bind to a folder with a given unique id?

Referendum answered 27/3, 2010 at 14:5 Comment(0)
Z
7

I had a similar problem and used urlencode/urldecode to make sure the ids was properly formatted. 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. 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.

Zahara answered 27/10, 2010 at 20:55 Comment(0)
D
0

Is the parentFolderId value correctly formed, or is it just throwing a wobbly when you try and instantiate the folder object? 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)

Decalogue answered 31/8, 2010 at 1:14 Comment(0)
M
-1

You need to make sure that the id is properly encoded. 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("[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();
    }
}

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>
Minneapolis answered 4/9, 2010 at 8:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.