Skip to content

Instantly share code, notes, and snippets.

@barisbikmaz
Last active July 10, 2023 08:49
Show Gist options
  • Save barisbikmaz/7a96e190ea99a60483d42c045823497d to your computer and use it in GitHub Desktop.
Save barisbikmaz/7a96e190ea99a60483d42c045823497d to your computer and use it in GitHub Desktop.
OneDrive FilePicker Example
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>file picker</title>
<style>
html,
body {
height: 100%;
width: 100%;
margin: 0;
display: flex;
justify-content: center;
}
iframe {
border: 1px;
}
</style>
<script
type="text/javascript"
src="https://res.cdn.office.net/teams-js/2.12.0/js/MicrosoftTeams.min.js"
></script>
</head>
<body>
<iframe id="pickerFrame" width="80%" height="50%"></iframe>
<script type="text/javascript">
var originDomain='https://localhost:9000';
var sharePointDomain='tenant.sharepoint.com';
var accessToken='a valid accessToken with files.read.all Sites.Read.All scope';
microsoftTeams.app.initialize().then(function () {
const pickerFrame = document.getElementById('pickerFrame');
const options = {
sdk: '8.0',
entry: {
sharePoint: {},
},
messaging: {
origin: originDomain,
channelId: '1234567',
},
typesAndSources: {
mode: 'folders',
},
};
const queryString = new URLSearchParams({
filePicker: JSON.stringify(options),
});
const pickerUrl = `https://${sharePointDomain}/_layouts/15/FilePicker.aspx?${queryString}`;
const form = pickerFrame.contentDocument.createElement('form');
form.setAttribute('action', pickerUrl);
form.setAttribute('method', 'POST');
const tokenInput =
pickerFrame.contentDocument.createElement('input');
tokenInput.setAttribute('type', 'hidden');
tokenInput.setAttribute('name', 'access_token');
tokenInput.setAttribute('value', accessToken);
form.appendChild(tokenInput);
pickerFrame.contentDocument.body.append(form);
form.submit();
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment