예제 #1
0
    public static async Task GetFileAsync()
    {
        var(authResult, message) = await Authentication.AquireTokenAsync();

        var httpClient = new HttpClient();
        HttpResponseMessage response;
        var request = new HttpRequestMessage(HttpMethod.Get, MainPage.fileurl);

        request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
        response = await httpClient.SendAsync(request);

        byte[] fileBytes = await response.Content.ReadAsByteArrayAsync();

        StorageLibrary videoLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Videos);

        string saveFolder   = videoLibrary.SaveFolder.Path;
        string saveFileName = App.Date + "-" + App.StartTime + "-" + App.IBX + "-" + App.Generator + ".xlsx";

        saveLocation = saveFolder + "\\" + saveFileName;
        using (MemoryStream stream = new MemoryStream())
        {
            stream.Write(fileBytes, 0, (int)fileBytes.Length);
            using (spreadsheetDoc = SpreadsheetDocument.Open(stream, true))
            {
                await Task.Run(() =>
                {
                    File.WriteAllBytes(saveLocation, stream.ToArray());
                    return(TaskStatus.RanToCompletion);
                });
            }
        }
    }