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/