如何在ProjectServer用代码修改用户属性?

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    = "http://ServerName/ProjectServerName/";
         const string RESOURCE_SERVICE_PATH = "_vti_bin/psi/resource.asmx";
         
         try
         {
            // Set up the resource object and dataset
            ResourceWebSvc.Resource resourceSvc = new ResourceWebSvc.Resource();
            ResourceWebSvc.ResourceDataSet resourceDs = new ResourceWebSvc.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);
         }
      }
   }
}

  

转载于:https://www.cnblogs.com/olay/archive/2012/10/17/2727020.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值