I am using Microsoft Graph API and I am trying to get Drive items that are inside a folder, this is what I got so far, I got most of this code from this Microsoft tutorial.
I get the drive items like so:
public static async Task<IEnumerable<DriveItem>> GetFilesAsync()
{
var graphClient = GetAuthenticatedClient();
var files = await graphClient.Me.Drive.Request().GetAsync();
return files.Items.CurrentPage;
}
And I call this method in my main controller:
[Authorize]
public async Task<ActionResult> Index()
{
var files = await GraphHelper.GetFilesAsync();
return View(files);
}
And then my view:
@model IEnumerable<Microsoft.Graph.DriveItem>
@{
ViewBag.Current = "Drive";
}
<table class="table">
<thead>
<tr>
<th scope="col">Name</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@item.Name</td>
</tr>
}
</tbody>
</table>
But when I run this code, I get this error:
Object reference not set to an instance of an object.
According to the stack, the error happens here:
var files = await graphClient.Me.Drive.Request().GetAsync();
What I am trying to accomplish is getting Files from my OneDrive that are in a certain folder.