I'm integrating YAF to my site using 1.9.3 BIN
I was just wondering, is it possible to use the default avatars and avatar upload of YAF, and use it for lets say the profiles in since the profiles inherit the YAF profiles...
So for example, if a user uploads a avatar on the forum, it shows on the site

Any idea on how to do this?
It jus me or theres not much support? (See lots of ananswered posts for weeks, "specially mine" )
Yep, I added a user's YAF avatar to my master page so it always appears in the upper right-hand corner.

I created a utility page called ~\utility\getavatar.aspx that accepts a user's GUID as an 'id' parameter, and then retrieves and returns the image from the database using LINQ to SQL.

protected void Page_Load(object sender, EventArgs e)


        protected void Page_Init(object sender, EventArgs e)
            if (Request.QueryString["id"] != null)
                string id = Request.QueryString["id"];

                if ( id != null && id != "" )
                    Response.ContentType = "image/png";

                    System.Drawing.Image image = RetrieveImage(id);
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    if (image != null)
                        image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

        private System.Drawing.Image RetrieveImage(string UserId)
            System.Drawing.Image image = null;
            string avatarPath = "";

                Aasp.DataAccess.Yaf_UserDataContext udc = new Aasp.DataAccess.Yaf_UserDataContext();
                var user = (from u in udc.yaf_Users
                           where u.ProviderUserKey == UserId.ToString()
                           select u).SingleOrDefault();

                if (user.Avatar != null && user.Avatar != "") avatarPath = user.Avatar;

                byte[] imageData = user.AvatarImage.ToArray();
                System.IO.MemoryStream memStream = new System.IO.MemoryStream(imageData);
                image = System.Drawing.Image.FromStream(memStream);
            catch (Exception)
                if (avatarPath == "")
                    avatarPath = Server.MapPath("noavatar.gif");
                    // c:\\Projects\\Aasp\\Aasp.WebSite\\utility\\noavatar.gif
                    string localPath = Server.MapPath("noavatar.gif");
                    localPath = localPath.Remove(localPath.LastIndexOf("\\"));
                    localPath = localPath.Remove(localPath.LastIndexOf("\\"));

                    // http://localhost:56922/member/forum//images/avatars/Other/3.gif
                    avatarPath = avatarPath.Substring(avatarPath.IndexOf(@"//") + 2);
                    avatarPath = avatarPath.Substring(avatarPath.IndexOf(@"/"));
                    avatarPath = avatarPath.Replace(@"//", @"/");
                    avatarPath = avatarPath.Replace(@"/", "\\");

                    avatarPath = localPath + avatarPath;

                image = System.Drawing.Image.FromFile(avatarPath);

            return image;

Then my masterpage has an image control, I set the ImageUrl to the utility page with the appropriate id.

<asp:Image ID="imgAvatar" runat="server" ImageUrl="<%#this.AvatarUrl%>" AlternateText="Member Summary" CssClass="LoginAvatar" />

protected string AvatarUrl
                string result = @"~/utility/getavatar.aspx?id=";
                MembershipUser mu = Membership.GetUser(HttpContext.Current.User.Identity.Name);
                if (mu != null)
                    result += mu.ProviderUserKey.ToString();
                return result;

UserPostedImage  | 
When I post fp:mddubs in a topic, I'm leaving my footprint there so I can track it once I get into coding/supporting. (Yes I stole this off Mek 🙂, who stole this off Ederon 🙂 )
  •  Jaben
  • 100% (Exalted)
  • YAF Developer
Another way to do this is just call the resource.ashx with the YAF UserID just as YAF does...


Would pretty simple to modify resource.ashx to support Membership Provider Keys in addition to YAF userid.
Jaben wrote:

Would pretty simple to modify resource.ashx to support Membership Provider Keys in addition to YAF userid.

I understand and know how to do the rest of the things you said.
But one question is, how do i make it the resource.ashx support membership provider keys?

It jus me or theres not much support? (See lots of ananswered posts for weeks, "specially mine" )

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved