私の要件は、招待状で送信されたファイルをダウンロードすることです。
イベントを取得するのに、List calendarView APIを使用しているようです。その場合は、応答から希望するEventリソースのイベント "id"プロパティを取得できるはずです。"id": "string (identifier)"
にチェックを入れてください。
その後、このイベントのすべての添付ファイルをList attachments APIで取得し、特別な添付ファイルをGet attachmentで取得できます。ファイルのbase64でコード化された内容を含むcontentBytes
プロパティによって、添付ファイルのバイナリ内容を取得できます。添付ファイルがfileAttachment resource typeの場合たとえば、添付ファイルが.txt
ファイルであれば、あなたはそれをダウンロードすることができ、次のようにアプリケーションlocal folderに保存します。
HttpClient client = new HttpClient();
string token =await AuthenticationHelper.GetTokenForUserAsync();
client.DefaultRequestHeaders.Add("Authorization", "Bearer "+token);
HttpResponseMessage httpresponse = await client.GetAsync(new Uri("https://graph.microsoft.com/v1.0/me/events/{id}/attachments/{id}"));
StorageFile downloadedfile = await ApplicationData.Current.LocalFolder.CreateFileAsync("attachment.txt",CreationCollisionOption.ReplaceExisting);
JObject resObj = JObject.Parse(await httpresponse.Content.ReadAsStringAsync());
string contentbyte = resObj["contentBytes"].ToString();
await FileIO.WriteTextAsync(downloadedfile, Encoding.UTF8.GetString(Convert.FromBase64String(contentbyte)));
更新: 添付ファイルが.txt
されていない場合、どのような実際に必要なことは正しくbase64で転送されますたとえば、内容をファイルにエンコードします。
StorageFile downloadedfile = await ApplicationData.Current.LocalFolder.CreateFileAsync("attachment.xlsx", CreationCollisionOption.ReplaceExisting);
string contentbyte = "contentbyte";
byte[] filecontent = Convert.FromBase64String(contentbyte);
await FileIO.WriteBytesAsync(downloadedfile, filecontent);
何を試してみましたか?また、動作が期待どおりにどうなりましたか?あなたの問題を解決するために作った努力(とコード)を表示することは、答えを引きつけるのに役立ちます。 –