8

クエリ文字列を介してクエリFolder.Id.UniqueIdから取得したフォルダのプロパティを別のページに渡します。FindFoldersこの2番目のページでは、これを使用し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));

同じ問題。

私はしばらく探していて、Base64 / UTF8変換に関するいくつかの提案を見つけましたが、それでも問題は解決しませんでした。

誰かが特定の一意のIDを持つフォルダにバインドする方法を知っていますか?

4

3 に答える 3

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.

于 2010-10-27T20:55:32.870 に答える
0

parentFolderId の値は正しく形成されていますか?それとも、フォルダー オブジェクトをインスタンス化しようとするとぐらつきますか? ID をクエリ文字列として渡す前に HttpUtility.UrlEncode を実行していますか (後で HttpUtility.UrlDecode を実行することを忘れないでください)。

于 2010-08-31T01:14:05.387 に答える
-1

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>
于 2010-09-04T08:06:32.510 に答える