Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 11th, 2008, 05:48 PM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jdelpay
Default Uploading image to profile

Does anyone know how users could upload a picture when creating their account, which would be loaded to their profile. thank you

 
Old April 13th, 2008, 07:12 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

In the UserProfile control, add the following code somehwere:

Code:
<asp:Panel ID="panFileUpload" runat="server">
<table cellpadding="2">
    <tr>
    The control below can be used to upload an avatar picture. In order to ensure it
    will not break our forum's layout, the maximum size of the image is 64kb.

    If the upload finishes succesfully, the url will automatically be entered into the 
    proper field for you.
    </tr>
    <tr>
        <td style="width: 110px;" class="fieldname">
        <asp:Label runat="server" ID="lblUploadFile" AssociatedControlID="txtTitle" 
            Text="Upload file:" /></td>
        <td style="width: 400px;">
        <EO:FileUploader id="FileUploader1" runat="server" Visible="true" /></td>
    </tr>
</table>
</asp:Panel>
And this is my full C# code:

[code]
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using EO.EntropiaOnline.BLL.Newsletters;

namespace EO.EntropiaOnline.UI.Controls
{
    public partial class UserProfile : System.Web.UI.UserControl
    {
        private string _username = "";
        public string UserName
        {
            get
            {
                return _username;
            }

            set
            {
                _username = value;
            }
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            this.Page.RegisterRequiresControlState(this);
        }

        protected override void LoadControlState(object savedState)
        {
            object[] ctlState = (object[])savedState;
            base.LoadControlState(ctlState[0]);
            _username = (string)ctlState[1];
        }

        protected override object SaveControlState()
        {
            // If the Uploader contains a fileUrl, a new upload happened.
            // This is the only place I can quickly add it, so this will
            // suffice for me for now.
            if (!string.IsNullOrEmpty(FileUploader1.FileUrl))
            {
                txtAvatarUrl.Text = FileUploader1.FileUrl;
                panFileUpload.Visible = false;
            }

            object[] ctlState = new object[2];
            ctlState[0] = base.SaveControlState();
            ctlState[1] = _username;
            return ctlState;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            // Set the text for the FileUploader to nothing, and the maxsize to 64k
            FileUploader1.LabelText = "";
            FileUploader1.MaxFileLength = 65536;

            if (!this.IsPostBack)
            {
                //ddlCountries.DataSource = Helpers.GetCountries();
                //ddlCountries.DataBind();

                // if the UserName property contains an empty string, retrieve the profile
                // for the current user, otherwise for the specified user
                ProfileCommon profile = this.Profile;
                if (this.UserName.Length > 0)
                    profile = this.Profile.GetProfile(this.UserName);

                ddlSubscriptions.SelectedValue = profile.Preferences.Newsletter.ToString();
                //ddlLanguages.SelectedValue = profile.Preferences.Culture;
                //txtFirstName.Text = profile.FirstName;
                //txtLastName.Text = profile.LastName;

                if (profile.BirthDate != DateTime.MinValue)
                    txtBirthDate.Text = profile.BirthDate.ToShortDateString();
                ddlGenderIRL.SelectedValue = profile.GenderIRL;
                txtOccupation.Text = profile.Occupation;
                txtLocation.Text = profile.Location;
                txtWebsite.Text = profile.Website;

                //txtStreet.Text = profile.Address.Street;
                //txtCity.Text = profile.Address.City;
                //txtPostalCode.Text = profile.Address.PostalCode;
                //txtState.Text = profile.Address.State;
                //ddlCountries.SelectedValue = profile.Address.Country;
                //txtPhone.Text = profile.Contacts.Phone;
                //txtFax.Text = profile.Contacts.Fax;

                txtSociety.Text = profile.InGame.Society;
                txtNameIngame.Text = profile.InGame.NameIngame;
                ddlGenderIngame.SelectedValue = profile.InGame.GenderIngame;

                txtTitle.Text = profile.Forum.UserTitle;
                txtAvatarUrl.Text = profile.Forum.AvatarUrl;
                txtSignature.Text = profile.Forum.Signature;
            }
        }

        public void SaveProfile()
        {
            // if the UserName property contains an empty string, save the current user's
            // profile, otherwise save the profile for the specified user.
            ProfileCommon profile = this.Profile;
            if (this.UserName.Length > 0)
                profile = this.Profile.GetProfile(this.UserName);

            profile.Preferences.Newsletter = (SubscriptionType)Enum.Parse(
                   typeof(SubscriptionType), ddlSubscriptions.SelectedValue);
            //profile.Preferences.Culture = ddlLanguages.SelectedValue;
            //profile.FirstName = txtFirstName.Text;
            //profile.LastName = txtLastName.Text;
            profile.GenderIRL = ddlGenderIRL.SelectedValue;
            if (txtBirthDate.Text.Trim().Length > 0)
                profile.BirthDate = DateTime.Parse(txtBirthDate.Text);
            profile.Occupation = txtOccupation.Text;
                //ddlOccupations.SelectedValue;
            profile.Website = txtWebsite.Text;

            //profile.Address.Street = txtStreet.Text;
            //profile.Address.City = txtCity.Text;
            //profile.Address.PostalCode = txtPostalCode.Text;
            //profile.Address.State = txtState.Text;
            //profile.Address.Country = ddlCountries.SelectedValue;
            //profile.Contacts.Phone = txtPhone.Text;
            //profile.Contacts.Fax = txtFax.Text;

            profile.InGame.Society = txtSociety.Text;
            profile.InGame.NameIngame = txtNameIngame.Text;
            profile.InGame.GenderIngame = ddlGenderIngame.SelectedValue;

            profile.Forum.UserTitle = txtTitle.Text;
            profile.Forum.AvatarUrl = txtAvatarUrl.Text;
            profile.Forum.Signature = txtSignature.Text;
            profile.Save();
        }
    }
}

Lastly, you will need to add the picture in the forum software. I did this in the ShowThread page, by inserting the following line(s):
Code:
<asp:Panel runat="server" ID="panAvatar" Visible='<%# GetUserProfile(Eval("AddedBy")).Forum.AvatarUrl.Length > 0 %>'>
<asp:Image runat="server" ID="imgAvatar" ImageUrl='<%# GetUserProfile(Eval("AddedBy")).Forum.AvatarUrl %>' /><br /><br />

http://entropia-online.blogspot.com/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Default image generation while uploading an image! ostwald ASP.NET 2.0 Professional 1 September 12th, 2007 01:44 AM
Image Uploading zaeem Classic ASP Databases 5 August 5th, 2006 05:53 PM
Uploading Image shurabhavesh ASP.NET 2.0 Basics 0 April 21st, 2005 05:49 AM
Image Uploading zaeem Classic ASP Basics 4 October 31st, 2003 03:06 AM
Uploading an Image zaeem Classic ASP Components 1 October 9th, 2003 09:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.