Last active
July 10, 2023 08:49
-
-
Save barisbikmaz/7a96e190ea99a60483d42c045823497d to your computer and use it in GitHub Desktop.
OneDrive FilePicker Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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