richards112
  • Posts: 19
  • Joined: 10/12/2008
Hi,
I'm integrating YAF to my asp.net 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 asp.net? 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?
Thanks
It jus me or theres not much support? (See lots of ananswered posts for weeks, "specially mine" )
Sponsor
mddubs
  • Posts: 476
  • Joined: 07/08/2008
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.

GetAvatar.aspx
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.Clear();
                    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);
                        ms.WriteTo(Response.OutputStream);
                    }
                }
            }
        }

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

            try
            {
                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");
                else
                {
                    // 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.

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


my.master.cs
protected string AvatarUrl
        {
            get
            {
                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 
www.bunkerhollow.com  | www.careercomputing.com 
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
  • Posts: 2544
  • Joined: 09/10/2004
Another way to do this is just call the resource.ashx with the YAF UserID just as YAF does...

e.g.:

http://forum.yetanotherf...net/resource.ashx?u=1587 

Would pretty simple to modify resource.ashx to support Membership Provider Keys in addition to YAF userid.
richards112
  • Posts: 19
  • Joined: 10/12/2008
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" )
Users browsing this topic
    Forum Jump  
    • You cannot post new topics in this forum.
    • You cannot reply to topics in this forum.
    • You cannot delete your posts in this forum.
    • You cannot edit your posts in this forum.
    • You cannot create polls in this forum.
    • You cannot vote in polls in this forum.

    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