Project server code automatically adds resources, users

Source: Internet
Author: User

First, we need to reference

Resource Web Service:

Http: // yourserver/PWA/_ vti_bin/psi/resource. asmx

Add assetSource codeAs follows:

 

Private guid addresource (string name, pslibrary. resource. type restype) {try {resds = new resourcews. resourcedataset (); resourcews. resourcedataset. resourcesrow resourcerow = resds. resources. newresourcesrow (); guid newresguid = guid. newguid (); resourcerow. res_uid = newresguid; resourcerow. res_name = Name; resourcerow. res_initials = Name. substring (0, 1) + (name. indexof ("")> 0? Name. substring (name. indexof ("") + 1, 1): ""); resourcerow. res_type = (INT) restype; resourcerow. res_group = "team members"; resourcerow. wres_email = string. format ("{0} @ {1 }. com ", name. substring (0, name. indexof (""), textboxname. text. substring (name. lastindexof ("") + 1, name. length-name. lastindexof ("")-1); resds. resources. addresourcesrow (resourcerow); ressvc. createresources (resds, false, true); Return newresguid;} catch (exception ex) {MessageBox. show (ex. message, "exception", messageboxbuttons. OK); Return guid. empty ;}}

 

If you want to add the resource as a login userCodeIt is not enough. You need to add the following code:

 
Private bool addauthorization (guid resourceuid, string account, bool windowsuser) {try {resourcews. resourceauthorizationdataset resourceauthds = new resourcews. resourceauthorizationdataset (); resourcews. resourceauthorizationdataset. resourcesrow resourceauthrow = resourceauthds. resources. newresourcesrow (); resourceauthrow. res_uid = resourceuid; resourceauthrow. res_is_windows_user = windowsuser; resourceauthrow. wres_account = Account; resourceauthds. resources. addresourcesrow (resourceauthrow); ressvc. setresourceauthorization (resourceauthds); Return true ;}catch {return false ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.