如何在codebehind中更新dotnetnuke userprofile图像?

Moh*_* JK 4 asp.net dotnetnuke dotnetnuke-module

我正在构建我自己的"user profile"模块,其中一个选项,用户可以更改其默认dnn配置文件图像.我在"代码背后"这样做时遇到了问题.我在用c#.

这是我到目前为止:

UserInfo myDnnUser = this.UserInfo;
myDnnUser.Profile.InitialiseProfile(PortalId);

myDnnUser.Profile.SetProfileProperty("Photo", "new filename");
myDnnUser.Profile.SetProfileProperty("PhotoURL", "new url");

ProfileController.UpdateUserProfile(myDnnUser);
Run Code Online (Sandbox Code Playgroud)

但它不起作用,当我查看dnn使用的"文件"表时,它仍然是相同的(旧)文件名.

有任何想法吗?

mik*_*ika 8

有三个表涉及:UserProfile,ProfilePropertyDefinitionFiles.

UserProfile存储ProfilePropertyDefinitions的PropertyValues.

"Photo"PropertyName的预期PropertyValue是对Files表的FileID引用,而不是文件名.在设置Photo之前,您需要获取FileID:

    var objFiles = new FileController();
    FileInfo objFile = objFiles.GetFile("filepath", PortalID);
    myDnnUser.Profile.Photo = objFile.FileId;
    ProfileController.UpdateUserProfile(myDnnUser);
Run Code Online (Sandbox Code Playgroud)

PhotoURL是一个只读属性,用于检索UserProfile的Photo属性的URL.