共用方式為


Resource.UpdateResources 方法

命名空間:  WebSvcResource
組件:  ProjectServerServices (在 ProjectServerServices.dll 中)

語法

'宣告
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Resource/UpdateResources", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Resource/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Resource/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function UpdateResources ( _
    rds As ResourceDataSet, _
    validateOnly As Boolean, _
    autoCheckIn As Boolean _
) As ResourceDataSet
'用途
Dim instance As Resource
Dim rds As ResourceDataSet
Dim validateOnly As Boolean
Dim autoCheckIn As Boolean
Dim returnValue As ResourceDataSet

returnValue = instance.UpdateResources(rds, _
    validateOnly, autoCheckIn)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Resource/UpdateResources", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Resource/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Resource/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public ResourceDataSet UpdateResources(
    ResourceDataSet rds,
    bool validateOnly,
    bool autoCheckIn
)

參數

  • validateOnly
    類型:System.Boolean

    如果true,只會驗證資料,而不會建立新的資源。

  • autoCheckIn
    類型:System.Boolean

    如果true,自動檢查中的資源資料。

傳回值

類型:WebSvcResource.ResourceDataSet
傳回的ResourceDataSet包含所做的變更。

備註

如果ResourceDataSet參數不包含的現有的資源資訊,則會建立資源,如果資源不存在於企業資源資料庫,或新資料來更新現有的資源, UpdateResources會刪除資源。

要修改或刪除每個資源需求來取出給目前已驗證的使用者呼叫UpdateResources之前。

Project Server 權限

權限

描述

ManageUsersAndGroups

可讓使用者管理所有企業使用者、 資源及群組。通用權限。

NewResource

可讓使用者建立新資源。通用權限。

ManageActiveDirectorySettings

可讓使用者管理使用者資訊。通用權限。

EditEnterpriseResourceData

可讓使用者編輯或刪除此資源。類別權限。

範例

下列範例會取得所有現有的企業資源的清單、 取出的第一個資源、 更新的資源名稱然後將變更儲存至伺服器並檢查該資源中。

Please see Prerequisites for Reference Code Samples for critical information on running this code sample.

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Windows.Forms;
using System.Web.Services.Protocols;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace Microsoft.Office.Project.Samples.UpdateResources
{
   class Program
   {
       static void Main(string[] args)
      { 
         const string PROJECT_SERVER_URI    = "https://ServerName/ProjectServerName/";
         const string RESOURCE_SERVICE_PATH = "_vti_bin/psi/resource.asmx";
         
         try
         {
            // Set up the resource object and dataset
            SvcResource.Resource resourceSvc = new SvcResource.Resource();
            SvcResource.ResourceDataSet resourceDs = new SvcResource.ResourceDataSet();            
            resourceSvc.Url = PROJECT_SERVER_URI + RESOURCE_SERVICE_PATH;
            resourceSvc.Credentials = CredentialCache.DefaultCredentials;

            // Read read all the resources
            resourceDs = resourceSvc.ReadResources(string.Empty, false);

            // Check out the first resource for updating.
            //  - This assumes the resource is checked in.
            //  - An error occurs if the resource is already checked out.
            resourceSvc.CheckOutResources(new Guid[] { resourceDs.Resources[0].RES_UID });

            // Update the resource name of the first row.
            Console.WriteLine ("Modifying resource " + resourceDs.Resources[0].RES_ID + " (" + resourceDs.Resources[0].RES_NAME + ")");
            resourceDs.Resources[0].RES_NAME += " Modified at: " + DateTime.Now.ToShortTimeString();

            // Send the update to the server and automatically check in the changed row
            resourceSvc.UpdateResources(resourceDs, false, true);
         }
         catch (System.Web.Services.Protocols.SoapException ex)
         {
            string errMess = "";
            PSLibrary.PSClientError error = new PSLibrary.PSClientError(ex);
            PSLibrary.PSErrorInfo[] errors = error.GetAllErrors();

            for (int j = 0; j < errors.Length; j++)
               errMess = errMess + errors[j].ErrId.ToString() + "\n";
            errMess = errMess + "\n" + ex.Message.ToString();

            MessageBox.Show(errMess, "Error", MessageBoxButtons.OK,
               MessageBoxIcon.Error);
         }
         catch (WebException ex)
         {
            string message = ex.Message.ToString() +
               "\n\nLog on, or check the Project Server Queuing Service";
            MessageBox.Show(message, "Project Creation Error",
               MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         catch (Exception ex)
         {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
         MessageBoxIcon.Error);
         }
      }
   }
}

請參閱

參照

Resource 類別

Resource 成員

WebSvcResource 命名空間