在不同子网站(SharePoint)中的文档库之间复制Word文档

时间:2014-02-24 19:49:55

标签: javascript jquery sharepoint sharepoint-2010 wsp

什么是最好的(主观的...我知道。抱歉!)方法,提示用户将我的库中的文档实例复制到他自己的网站中的库(在相同的网站集上,如果这很重要) ?我是一个管理员,有一些word文档,我经常创建它们来设置特定的内容类型。所以我创建了一个包含一些单词模板的库,供他们复制(最重要的是:除了修改/创建的字段外,还包括元数据)。

我尝试了一些javascript / jquery方法,我将这些方法放在显示表单上,文本框允许他们输入他们的库网址以及他们想制作多少副本,但这似乎不是按照我的意愿工作。实现这一目标的最有效方法是什么?使用事件处理程序?如果是这样,有没有办法将其中一个与功能区上的自定义按钮相关联(我只将这些按钮与js功能相关联)?

我尝试使用的javascript函数示例:

function copyItem() {
    var itemurl = $("#copyFrom").val();
    var dst = $("#copyTo").val();

    $().SPServices({
        operation: "GetItem",
        Url: itemurl,
        async: false,
        completefunc: function (xData, Status) {
            itemstream = $(xData.responseXML).find("Stream").text();
            itemfields = "";
            $(xData.responseXML).find("FieldInformation").each(function(){
                itemfields+=$(this).get(0).xml;
            });;

        }
    });

    $().SPServices({
        operation: "CopyIntoItems",
        SourceUrl: itemurl,
        async: false,
        DestinationUrls: [dst],
        Stream: itemstream,
        Fields:itemfields,
        completefunc: function (xData, Status) {
            var error = $(xData.responseXML).find("CopyResult").first().attr("ErrorCode");
        }
    }
}

呼叫:

  <label>from:</label><input type="text" value="" id="copyFrom" maxlength="255">
    <label>to:</label><input type="text" value="" id="copyTo" maxlength="255">
    <input type="button" onclick="copyItem();" value="Copy">

注意:我现在没有在这些文本框中输入任何值,因为我手动将它们输入到itemurl和dst中。 但控制台说:

  

属性'copyItem'的值为null或undefined,而不是Function对象。

1 个答案:

答案 0 :(得分:0)

不建议使用“async:false”。最好是进行异步调用,然后将第二个SPServices插入第一个。

第二个SPServices也缺少一个紧密的括号。

最后,“Fields”必须是一个数组(http://msdn.microsoft.com/en-us/library/copy.copy.copyintoitems.aspx)。

我尝试了以下代码,它对我有用:

var srcurl="http://my.sharepoint.com/aymeric_lab/Shared%20Documents/879258.jpeg";
var desturl="http://my.sharepoint.com/aymeric_lab/Shared%20Documents/879258_copy.jpeg";
$().SPServices({
  operation: "GetItem",
  Url: srcurl,
  completefunc: function (xData, Status) {
    var itemstream = $(xData.responseXML).find("Stream").text();
    var itemfields = [];
    $(xData.responseXML).find("FieldInformation").each(function(){
      itemfields.push($(this).get(0).xml);
    });

    $().SPServices({
      operation: "CopyIntoItems",
      SourceUrl: srcurl,
      DestinationUrls: [ desturl ],
      Stream: itemstream,
      Fields:itemfields,
      completefunc: function (xData, Status) {

      }
    })
  }
});
相关问题