1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Profile Photo or Default Avatar

Profile Photo or Default Avatar

5 posts, 0 answered
  1. Philip Senechal
    Philip Senechal avatar
    69 posts
    Registered:
    07 Apr 2008
    23 Apr 2010
    Link to this post
    I can't seem to figure this out...

    I am storing Profile Photos, if they are uploaded, in an Image library called Profile_Photos. What I would like to do, is if the user that is currently logged in has uploaded a photo, display that on the page, otherwise display the defaultavatar image. I uploaded the defaultavatar image to the same library in case I need to reference it there. Can someone explain to me how I can do this?

    I tried using Profile.Photo for the image URL and checking to see if it's blank. But apparently if you upload an image to your profile and then delete the image from the library, the path still remains in the Profile.Photo value.

    So I then I tried using if(File.Exists(Profile.Photo)), but this doesn't seem to recognize it when the file is there...I'm assuming because the image is being stored in the database.

    Any ideas? Thanks!
  2. Philip Senechal
    Philip Senechal avatar
    69 posts
    Registered:
    07 Apr 2008
    23 Apr 2010
    Link to this post
    or perhaps I need to remove the row from the telerik_UserMetaInfo table when I allow the user to delete their profile photo? Is that a better approach?
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    25 Apr 2010
    Link to this post
    Hi Philip Senechal,

    The default image that is loaded is stored under ~/Sitefinity/Common/Images/defaultavatar.gif. There is no implementation for removing the image and setting the default one. You could implement a link button under Sitefinity\Admin\CmsAdmin\Users.aspx to restore the default value of the image - Restore or Delete button.

    To get/set an image of the currently logged in user you could use the methods below


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  4. Philip Senechal
    Philip Senechal avatar
    69 posts
    Registered:
    07 Apr 2008
    28 Apr 2010
    Link to this post
    I tried executing the following to no avail...

    MembershipUser user = Membership.GetUser();
    string UserName = user.UserName;
    ProfileBase profileBase = ProfileBase.Create(UserName, true);
    profileBase.SetPropertyValue("Photo", "~/Sitefinity/Common/Images/defaultavatar.gif");
    profileBase.Save();
     
    Label1.Text = profileBase.GetPropertyValue("Photo").ToString();

    The value doesn't seem to change when I execute this code. Can you let me know if I'm doing something wrong here?

    It looks like all the Sitefinity profile information is being written to telerik_UserMetaInfo, not telerik.Profile. Do I need to use a different method to update the values in UserMetaInfo as opposed to Profile? Thanks.
  5. Philip Senechal
    Philip Senechal avatar
    69 posts
    Registered:
    07 Apr 2008
    28 Apr 2010
    Link to this post
    I figured it out. If I just used Profile.SetPropertyValue() instead of declaring my own ProfileBase(), it worked fine. Maybe they were conflicting??? Who knows...anyways, those methods work to reset the value to the default. Thanks.
Register for webinar
5 posts, 0 answered