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 ;}}