以编程方式从远程计算机更新sharepoint列列值

时间:2014-08-19 14:19:48

标签: asp.net sql-server web-services sharepoint

我有一个asp网站,它使用SSIS读取共享点列表并将其显示在网格视图上。然后,在单击按钮时,SQL数据库中的表将使用某些列表值进行更新。我想要的是,对于按钮单击也更新共享点列表上的列,以便再次运行时SSIS包将忽略该行。并且网站和sharepoint位于不同的服务器上。哪种方法最好?

1 个答案:

答案 0 :(得分:0)

因为它位于不同的服务器上,我建议使用SharePoint Web服务和AJAX。以下是更新任务项的AJAX示例:

function updateTaskPercent(taskId, pctComplete, taskStatus) {
    var targetUrl = "../_vti_bin/lists.asmx";
    var listName = "Project Tasks";
    var updateItemXml;
    updateItemXml =
        "<Batch OnError=\"Continue\" ListVersion=\"1\" ViewName=\"\">" +
        "<Method ID=\"1\" Cmd=\"Update\">" +
        "<Field Name=\"ID\">" + taskId + "</Field>" +
        "<Field Name=\"Status\">" + taskStatus + "</Field>" +
        "<Field Name=\"_x0025__x0020_Complete\">" + pctComplete + "</Field>" +
        "</Method>" +
        "</Batch>";
    var soapEnv = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        " <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>     <UpdateListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">" +
        "       <listName>" + listName + "</listName>" +
        "       <updates>" + updateItemXml + "</updates>" +
        "     </UpdateListItems>  </soap:Body></soap:Envelope>";
    $.ajax({
        cache: false,
        url: targetUrl,
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        contentType: "text/xml; charset=utf-8",
        beforeSend: function(xhr) {
            xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
        },
        complete: function(msg) {
            if ($(msg.responseXML).find("ErrorText").text().length === 0) { // success
                SP.UI.Status.removeAllStatus(true);
                addNotification("Task Updated");
            } else {
                //Failure
                var errorString = $(msg.responseXML).find("ErrorText").text();
                if (errorString.length === 0) {
                    errorString = $(msg.responseXML).find("FaultString").text();
                }
                errorString = errorString.replace(/(\r\n|\n|\r)/gm, "");
            }
        }
    });
}
相关问题