4

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?

huMpty duMpty
  • 14,346
  • 14
  • 60
  • 99
Mohsin JK
  • 561
  • 2
  • 8
  • 18

1 Answers1

8

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.

mika
  • 6,812
  • 4
  • 35
  • 38