sharepoint 2013 修改用户配置文件属性值方法 modify user profile

在之前写过两篇关于sharepoint 的UserProfile博客

sharepoint 2010 获取用户信息UserProfile方法

sharepoint 2010 如何用SocialCommentManager获取记事板评论数据

这里顺便记录一下,如何通过程序,来更新UserProfile的属性所对应的字段值。

1.引用几个dll.

Microsoft.Office.Server.dll,

Microsoft.Office.Server.UserProfiles.dll

Microsoft.Sharepoint.dll

2.创建一个控制台应用程序。在Main方法中,执行如下方法。

SPSecurity.RunWithElevatedPrivileges(delegate()

            {

                try

                {

                    using (SPSite site = newSPSite(BasePage.siteURL))//服务器Url

                    {

                        SPServiceContext context = SPServiceContext.GetContext(site);

                        UserProfileManager profileManager = newUserProfileManager(context);

                        string sAccount = "dev\\chenxinxian";//域名\用户名

                        UserProfile u =profileManager.GetUserProfile(sAccount);

                        u[PropertyConstants.FirstName].Value = "新贤";//名字

                        u[PropertyConstants.LastName].Value = "";//姓氏

                       u.DisplayName = "陈新贤";

                        u.Commit();

                    }

                }

                catch (UserNotFoundException exception)

                {

                    Console.WriteLine(exception.ToString());

                }

            });

但是我们发现,在执行的过程中,会出现一个错误。

UserProfileApplicationNotAvailableException_Logging :: UserProfileApplicationProxy.ApplicationProperties ProfilePropertyCache does not have b01f37cc-f782-4f02-85a3-62ec01eb113c

 

这个错误,经过各方面的资料查找,最终发现,是因为权限的问题。解决这个错误的方法,如下:

接下来,把新加入的帐号,勾选中完全控制.点击确定。

最后我们发现,我们更新的用户信息,已经更新到UserProfile了。

这是关于sharepoint 的userprofile更新数据的程序。

 

 

 

可以使用cJSON库来处理JSON文件。以下是一个将JSON文件中某个属性修改后写回文件的示例代码: ```c #include <stdio.h> #include <stdlib.h> #include "cJSON.h" void modify_json_value(const char* filename, const char* key, const char* new_value) { // 读取JSON文件 FILE* fp = fopen(filename, "rb"); if (!fp) { printf("Failed to open file: %s\n", filename); return; } fseek(fp, 0, SEEK_END); long file_size = ftell(fp); fseek(fp, 0, SEEK_SET); char* json_str = (char*)malloc(file_size + 1); fread(json_str, 1, file_size, fp); fclose(fp); json_str[file_size] = '\0'; // 解析JSON cJSON* root = cJSON_Parse(json_str); if (!root) { printf("Failed to parse json string: %s\n", json_str); free(json_str); return; } // 修改属性 cJSON* node = cJSON_GetObjectItem(root, key); if (node) { cJSON_ReplaceItemInObject(root, key, cJSON_CreateString(new_value)); } else { printf("Failed to find key: %s\n", key); cJSON_Delete(root); free(json_str); return; } // 生成新的JSON字符串 char* new_json_str = cJSON_Print(root); cJSON_Delete(root); free(json_str); // 写回文件 fp = fopen(filename, "wb"); if (!fp) { printf("Failed to open file: %s\n", filename); free(new_json_str); return; } fwrite(new_json_str, 1, strlen(new_json_str), fp); fclose(fp); free(new_json_str); } int main() { modify_json_value("example.json", "name", "new_name"); return 0; } ``` 在这个示例中,我们首先读取JSON文件,并使用cJSON_Parse函数将其解析为一个cJSON对象。然后,我们使用cJSON_GetObjectItem函数查找要修改属性节点,并使用cJSON_ReplaceItemInObject函数将其替换为一个新的节点。最后,我们使用cJSON_Print函数将修改后的JSON对象转换为字符串,并将其写回原来的文件中。 需要注意的是,由于在修改JSON文件时需要重新生成整个JSON字符串,因此在处理大型JSON文件时可能会导致性能问题。如果需要频繁地修改JSON属性,建议使用其他格式的数据存储,如数据库。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值