SharePoint 2010:如何使用 javascript 将文件上传到文档库
我看到这篇文章解释如何使用客户端 API 从完全受信任的应用程序上传文件。
如何通过 javascript 实现这样的功能?
例如,我有这段代码,其中既有文件的本地路径又有 SharePoint 文档库,我该如何完成它?
谢谢!
PS:我猜测客户端中必须涉及一些完全受信任的组件才能实现这一目标,否则将出现 javascript 安全漏洞,但是在这种情况下针对 SharePoint 使用哪个组件是正确的?
<script type="text/javascript">
var list;
var filePath;
function ShowUploadDialog() {
// get file path user chooses through a dialog
var fileDialog = document.getElementById("fileDialog");
fileDialog.click();
filePath = fileDialog.value;
// get list
var context = new SP.ClientContext.get_current();
var site = context.get_site();
var web = site.get_rootWeb();
this.collList = web.get_lists();
list = collList.getByTitle("My doc library");
context.load(list);
context.executeQueryAsync(Succeeded, Failed);
}
function Succeeded(sender, args) {
// I HAVE HERE THE list AND THE filePath, HOW CAN UPLOAD THE FILE TO THE LIST?
}
function Failed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
I see this article explaining how to upload a file using client API's from a fully trusted app.
How to implement such functionality but from javascript?
For example, I have this code in which I have both the local path of the file and the SharePoint doc lib, how do I complete it?
Thanks!
PS: I'm guessing there must be some fully trusted component involved in the client in order to achieve this, otherwise would be a javascript security hole, but which one would be the right one to use in this case against SharePoint?
<script type="text/javascript">
var list;
var filePath;
function ShowUploadDialog() {
// get file path user chooses through a dialog
var fileDialog = document.getElementById("fileDialog");
fileDialog.click();
filePath = fileDialog.value;
// get list
var context = new SP.ClientContext.get_current();
var site = context.get_site();
var web = site.get_rootWeb();
this.collList = web.get_lists();
list = collList.getByTitle("My doc library");
context.load(list);
context.executeQueryAsync(Succeeded, Failed);
}
function Succeeded(sender, args) {
// I HAVE HERE THE list AND THE filePath, HOW CAN UPLOAD THE FILE TO THE LIST?
}
function Failed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UploadCtl 解决了这个问题。
UploadCtl solves this.