Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I am setting up membership for a site, and would like to give the members the possibility to upload one or more pictures to their profile.
What is the best practice regarding this? I have created a control that allows the members to edit their profile, but I am not sure I wish to include a Media Picker in that profile editor.
How should I approach this?
Why not use an upload control? Have I missed something important?
That is to day, a property on your membertype of type 'upload'.
They could upload anything (pdf, swf, etc.) so you'd want to do some checking that it is really an image before you try to display it.
You haven't missed anything ;-) I think I have.
Just to spell it out... if I add an upload control to the member type, and use the umbraco editor controls to render the members "edit profile" page, then I need to save the image somewhere, and I guess that is in the media section. When I use the Edit Member page in the umbraco backend, it just uploads the image to the media section, but it isn't displayed anywhere.
Where is the value saved? And is there example code to handle that upload? I have just created a user control that looks at the member type and displays the controls on there. I have yet to handle all specific controls... upload being one of them.
When I try to upload an image using the uploadField, it just goes wrong. I get this exception:
[InvalidOperationException: Invalid attempt to read when no data is present.]
System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i, Boolean setTimeout) +778859
System.Data.SqlClient.SqlDataReader.GetGuid(Int32 i) +29
umbraco.DataLayer.RecordsReaderAdapter`1.GetGuid(String fieldName) in d:\TeamCity\buildAgent\work\7380c184e9fcd3ea\umbraco\datalayer\RecordsReaderAdapter.cs:263
TestSite.MemberProfile.SaveControlValue(Control c, Member m, String prop) in C:\Development\Test\TestSite\MemberProfile.ascx.cs:298
TestSite.MemberProfile.saveBtn_Click(Object sender, EventArgs e) in C:\Development\ Test\TestSite\MemberProfile.ascx.cs:238 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
The code I use to upload is pretty simple, and something I got from looking at the Umbraco source code on Codeplex. I am not sure it is correct though:
uploadField uf = ((uploadField)ctrl);
if (uf.PostedFile.ContentLength > 0)
I think this goes wrong when it tries to delete the existing file. But I am not sure.
Ok... cleaning up some other code seems to have made this work. It works now in any case, without me touching the code ;-)
So where does this end up? I cannot browse the image in the media section.
The upload datatype stores files in /media folder on disk, but doesn't create a media item, so you can't see it there. You could however easily create the media object yourself programmatically, but it wouldn't be linked to the member. If you want your member's images tored in the media section, I'd create a media item programmatically, and link that to the member instead.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted