I am building my own "user profile"
module where one of the options, the user can change his default dnn
profile image. I am having problems doing this "in the code behind". I am using c#
.
This is what I have so far:
UserInfo myDnnUser = this.UserInfo;
myDnnUser.Profile.InitialiseProfile(PortalId);
myDnnUser.Profile.SetProfileProperty("Photo", "new filename");
myDnnUser.Profile.SetProfileProperty("PhotoURL", "new url");
ProfileController.UpdateUserProfile(myDnnUser);
But its not working, and when I view the "File" table that dnn uses, its still the same (old) filename.
Any ideas?
There are three tables involved: UserProfile
, ProfilePropertyDefinition
and Files
.
UserProfile stores PropertyValues for ProfilePropertyDefinitions.
Expected PropertyValue for a "Photo" PropertyName is a FileID reference to the Files table, not a file name. Before setting the Photo, you need to get the FileID:
var objFiles = new FileController();
FileInfo objFile = objFiles.GetFile("filepath", PortalID);
myDnnUser.Profile.Photo = objFile.FileId;
ProfileController.UpdateUserProfile(myDnnUser);
PhotoURL is a read-only property that retrieves the url for the UserProfile's Photo property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With