Function getFileByPath

  • Retrieves a file by its path or folder ID within a SharePoint drive.

    Parameters

    • client: Client

      The Microsoft Graph client instance.

    • options: {
          driveId: string;
          filePath?: string;
          responseType?: ResponseType;
      }

      An object containing the drive ID and file location details.

      • driveId: string

        The ID of the drive containing the file.

      • OptionalfilePath?: string

        The relative path to the file within the drive (optional if folderId is used).

      • OptionalresponseType?: ResponseType

        Optional. The response type (e.g., ResponseType.ARRAYBUFFER).

    Returns Promise<any>

    A promise that resolves to the file content.

    const file = await getFileByPath(client, {
    driveId: 'your-drive-id',
    filePath: 'Reports/2025/Report.pdf',
    responseType: ResponseType.ARRAYBUFFER,
    });
    console.log(file);