【问题标题】:Is it Possible to upload file to SharePoint Doc libary with jquery?是否可以使用 jquery 将文件上传到 SharePoint Doc 库?
【发布时间】:2013-08-18 15:15:50
【问题描述】:

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

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

这是目标:
1)解决方案应该是我粘贴的代码块;而不是 Web 部件或已编译的解决方案或应用程序。
2) 而且我不想使用本机 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 服务的客户端代码。

【问题讨论】:

    标签: c# jquery web-services rest sharepoint


    【解决方案1】:

    你可以用我的两个项目做到这一点:

    1. FileToDataURI:从用户那里读取文件的跨浏览器解决方案(现代浏览器使用 FileAPI,旧浏览器使用 Flash)...它将读取本地文件的内容
    2. SharepointPlus createFile():将阅读的内容上传到Sharepoint

    我将它用于我的一个 Sharepoint 网站(内部网),它适用于所有浏览器。

    【讨论】:

      【解决方案2】:

      以下代码将 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"/>
      

      【讨论】:

      • 你确定吗?我用 Firefox 测试,在文档共享库中创建了一个文件,但是当我的原始文件为 15KB 时,它包含 1KB,并且内容已损坏...
      猜你喜欢
      • 1970-01-01
      • 2013-12-12
      • 1970-01-01
      • 2011-08-15
      • 2020-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-06
      相关资源
      最近更新 更多