c# - 是否可以使用 jquery 将文件上传到 SharePoint 文档库?

标签 c# jquery web-services rest sharepoint

是否可以使用 jquery 代码将文档上传到 SharePoint 文档库?

客户端是否有与 asp:fileupload 等效的控件来选择文件?

目标是:
1)解决方案应该是我粘贴的代码块;而不是 Web 部件或编译的解决方案或应用程序。
2) 我不想使用 native SharePoint 文件上传或编辑表单页面来设置元数据。

创建一个新的 SharePoint aspx 页面:

  • 使用户能够以特定硬编码用户的身份将所选文件上传到特定 SharePoint 文档库
  • 将文件重命名为某个随机的唯一序列,如果:
  • 该文件尚不存在。
  • 文件必须是特定文件类型 (pdf)
  • 必须能够为文件设置一些元数据列值

这些链接让我相信这是可能的:

http://msdn.microsoft.com/en-us/library/ms454491(v=office.14).aspx

http://blog.yahoo.com/lamung/articles/91696

Upload a file to SharePoint through the built-in web services

我将支付可行的解决方案费用。理想情况下,只有使用 Web 服务的客户端代码。

最佳答案

以下代码将 pdf 上传到文档库。这可能对你有一些帮助

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script><script src="/Style%20Library/jquery.SPServices-0.6.2.min.js" type="application/javascript"></script><script src="/Style%20Library/jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
   function uploadFile() {

    var filePath = "c:\\test.pdf";
    var url= "http://Site/Shared Documents/test.pdf";

    var soapEnv =
    "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
        <soap:Body>\
            <CopyIntoItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>\
                <SourceUrl>" + filePath + "</SourceUrl>\
                    <DestinationUrls>\
                        <string> "+ url + "</string>\
                    </DestinationUrls>\
                    <Fields>\
                        <FieldInformation Type='Text' DisplayName='Title' InternalName='Title' Value='Test' />\
                    </Fields>\
                <Stream>base64Binary</Stream>\
            </CopyIntoItems>\
        </soap:Body>\
    </soap:Envelope>";

    $.ajax({
        url: "http://site/_vti_bin/copy.asmx",
        beforeSend: function (xhr) { xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems"); },
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset=\"utf-8\""
    });
    alert(soapEnv);
}


function processResult(xData, status) {
    alert("Uploaded SuccessFully");
}
 </script>
<input name="Upload" onclick="uploadFile()" type="button"/>

关于c# - 是否可以使用 jquery 将文件上传到 SharePoint 文档库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18269518/

相关文章:

xml - 如何使用 Postman 将 XML 数据发布到 Web 服务?

android - 使用 Ion android 网络库的问题

c# - 优先级默认值或其他函数? (重载)

c# - 使用任务的经典永无止境的线程循环?

c# - 为什么 PdfSharp 在网络链接周围创建边框?

javascript - 在页面刷新时随机更改 HTML 背景

javascript - 按下 Enter 按钮时触发按钮

c# - 激活 key 保存在哪里

javascript - 根据情况改变img来源

java - maven在java中生成Web服务