SharePoint 2010:如何使用 javascript 将文件上传到文档库

发布于 2024-11-06 22:19:52 字数 1386 浏览 0 评论 0原文

我看到这篇文章解释如何使用客户端 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可爱暴击 2024-11-13 22:19:52

UploadCtl 解决了这个问题。

UploadCtl solves this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文