Site structure
Version 4.x > Site structure > Forum Avatar View modes: 
User avatar
Member
Member
nnarayanan - 11/12/2009 1:27:16 PM
   
Forum Avatar
Instead of uploading an actual image for avatar in kentico, can I define a path some how to grab the images?

Thanks in advance.

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 11/17/2009 9:08:12 AM
   
RE:Forum Avatar
Hello,

Could you please describe the requested functionality further? Maybe some examples would help us to see, what do you want to accomplish.

Best regards,
Boris Pocatko

User avatar
Member
Member
vspudic - 11/18/2009 9:39:36 AM
   
RE:Forum Avatar
Hello,

Here are some specifics: (The original poster and I work together!)

We want avatars in the forum module to be pulled from a file path as opposed to the binary image field in the avatar table. I see that I can use the API to specify a UserPicture for a UserInfo object. This ends up in the field CMS_UserSettings.UserPicture.

How to I make this image render on the user's forum posts?

Thank you!

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 11/19/2009 10:09:02 AM
   
RE:Forum Avatar
Hello,

If I understand your requirement correctly, you don't want to store the files in the database? If I am wrong, could you please create a simple example for clarification? Otherwise you need just to change the option store files in database to store files in file system. Please see the attached file for more information abbout these settings.

http://devnet.kentico.com/docs/devguide/where_the_files_are_stored.htm

Best regards,
Boris Pocatko

User avatar
Member
Member
vspudic - 11/19/2009 10:32:52 AM
   
RE:Forum Avatar
Thank you Boris.

Generally, we do want to store files in the database. Our forum users, however, already exist on another site with which we are integrating our Kentico site. The users already have avatars on this other site, stored as files. These files are accessible by our Kentico site.

I was hoping that we could use some sort of parameter such that only avatar images are pulled from the file system - not all files. Otherwise, I may have to customize every forum component to use the image path! :(

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 11/24/2009 10:28:41 AM
   
RE:Forum Avatar
Hello,

I checked with our developer responsible for the forum module and the only way for doing this is to create a simple program, which would load your images into our database as the user avatar picture. You can use the

CMS.SiteProvider ► AvatarInfoProvider ►SetAvatarInfo(AvatarInfo)

method. You need to load the files, find the user which is associated with the avatar in our CMS and set it. The file has to be saved into the AvatarBinary property of the AvatarInfo object. You may use the File.ReadAllBytes method (.NET functionality) to get the byte stream. For more information about Kentico API please see our API reference (link).

Edited 26.11.2009, method corrected.

Best regards,
Boris Pocatko

User avatar
Member
Member
vspudic - 11/24/2009 10:32:18 AM
   
RE:Forum Avatar
Thank you again, Boris. I think we will try this approach.

User avatar
Member
Member
vspudic - 11/25/2009 4:07:06 PM
   
RE:Forum Avatar
Boris,

The API documentation for AvatarInfoProvider is thorough in some ways but the explanations for what each method actually does leave me mostly in the dark!

So, I have a file on the fileSystem and I want to load the file into the CMS_Avatar table. Then, I want to associate that avatar with a particular user. Questions:

1. Does SaveAvatarFileToDisk actually save the file to disk or to the database? I've executed the code without error and do not see a new record in the CMS_Avatar table... I already have it on disk, so I am not sure if this is the correct approach.

2. What is the difference between UploadAvatar and SaveAvatarFileToDisk?

3. Once I figure out how to get the avatar into the database, how do I use the AvatarInfoProvider to retrieve the avatarID of the one I just uploaded? I will need to set my UserInfo.UserAvatarID to this.

Any information you can provide would be really helpful. I've found your API incredibly powerful - when I can understand how to use it.

Thank you again,
Valerie

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 11/26/2009 11:21:28 AM
   
RE:Forum Avatar
Hello,

Please find my answers bellow:

1) I am sorry, there was a misunderstanding, please use the CMS.SiteProvider ► AvatarInfoProvider ► SetAvatarInfo(AvatarInfo) method for this. Also if you use this method it depends on your site settings, if the file is saved in the file system or in the database. If you have checked save files in database, it saves it into the database and creates an entry. If you have the other option enabled, it saves it on the file system and also creates a database entry.

2) The UploadAvatar method is used only if there is some avatar available, and needs to be replaced. All the information are updated for the avatar picture.

3) If you use the SetAvatarInfo(AvatarInfo) method you have a AvatarInfo object created, which has the AvatarId property.

Once more I am sorry for the mixup.

Best regards,
Boris Pocatko

User avatar
Member
Member
vspudic - 12/2/2009 11:53:20 AM
   
RE:Forum Avatar
Hi Boris,

Thank you for the clarification and for your help. The misunderstanding was mostly on my part!

I have it working with these lines of code:

AvatarInfo ai = new AvatarInfo("\\\\server\\share\\path\\image.gif");
ai.AvatarType = "User";
ai.AvatarIsCustom = true;
AvatarInfoProvider.SetAvatarInfo(ai);

Thanks again!

-Valerie