MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

How to add additional picture in user profile?  (Mono Support )

Viewed 32214 time(s), 11 post(s) 12/11/2012 4:55:48 PMby devmonox
devmonox

devmonox

12/11/2012 4:55:48 PM
Can you please give any idea that how can i add addtional picture of any user? The requirement is that with profile picture user should be able to select one extra image as cover picture like facebook/twitter.
This content has not been rated yet. 
52 Reputation 6 Total posts
khorvat

khorvat

12/12/2012 8:34:07 AM
Hi,

one easy way would be to use the UploadModule.ascx & FileGallery.ascx module. Both modules would have to be set with following settings:

ParentEntityType = SnEntityType.User
ParentEntityId = Here you should set the id of the profile owner user

Another option would be to create a separate table in the database, connect it with 1:1 FK connection then upload the image to some folder , save the path to table or upload directly to that table and then show that image beside the avatar on the profile.

Let us know which approach suites you better so we can proceed.

Regards
Rated 5.00, 1 vote(s). 
15993 Reputation 2214 Total posts
devmonox

devmonox

12/12/2012 9:53:37 AM
Thanks for quick response. I will go with modules approach as that seems to work for me without structural changes of database.
This content has not been rated yet. 
52 Reputation 6 Total posts
khorvat

khorvat

12/12/2012 10:12:15 AM
Ok, great, here is what you need to do

Add the following to your page
 
<%@ Register Src="/MonoX/ModuleGallery/UploadModule.ascx" TagPrefix="mono" TagName="UploadModule" %>
<%@ Register TagPrefix="MonoX" TagName="FileGallery" Src="/MonoX/ModuleGallery/SocialNetworking/FileGallery.ascx" %>
...
<mono:UploadModule ID="uploadModule" runat="server"></mono:UploadModule>
<MonoX:FileGallery ID="fileGallery" runat="server" PageSize="1"></MonoX:FileGallery>
//Then add the following C# code to the OnInit or OnLoad page event
 
fileGallery.ParentEntityType = SnEntityType.User;
uploadModule.ParentEntityType = SnEntityType.User;
 
fileGallery.ParentEntityId = this.UserId; //(Only if you are on the MonoX user profile pages)
uploadModule.ParentEntityId = this.UserId; //(Only if you are on the MonoX user profile pages)
Regards
Rated 5.00, 1 vote(s). 
15993 Reputation 2214 Total posts
devmonox

devmonox

12/12/2012 11:26:30 AM
Thanks. I appriciate your help.
1- When you say add to your page, it means i need to add into EditProfile.ascx. Right?
2- The c# code is will do all the trick to save etc. Right?


Edited
======
I tried putting code in editprofile.ascx and it gives me this error when i click upload button.

Exception Details: System.Data.SqlClient.SqlException: The INSERT statement conflicted with the FOREIGN KEY
constraint "FK_SnRelationship_aspnet_Users". The conflict occurred in database "MonoXDB", table "dbo.aspnet_Users", column 'UserId'.
The statement has been terminated.

Source Error:

Line 494: {
Line 495: SnRelationshipEntity newRelationship = CreateRelationship(parentId, entityType);
Line 496: SaveEntity(newRelationship, true);
Line 497: return newRelationship;
Line 498: }
This content has not been rated yet. 
52 Reputation 6 Total posts
devmonox

devmonox

12/12/2012 12:05:20 PM
It works for me finally when i put everything in UserProfileModule.ascx. Many thanks for it and it works because you helped me.

I can i can upload as many as user want with this module. But want is to upload only one file and if user upload any other, it should replace the existing one. Is it possible?


This content has not been rated yet. 
52 Reputation 6 Total posts
khorvat

khorvat

12/12/2012 12:21:37 PM
Thanks ...
It works for me finally when i put everything in UserProfileModule.ascx. Many thanks for it and it works because you helped me.
I can i can upload as many as user want with this module. But want is to upload only one file and if user upload any other, it should replace the existing one. Is it possible?
With the built-in functionality, no ... you will have to add a few lines of code to accomplish this.

- you will have to attache a method to an FileUploaded event in order to delete any existing files with that relation
uploadModule.FileUploaded += new EventHandler<FileUploadEventArgs>(uploadModule_FileUploaded);
in the uploadModule_FileUploaded you will have to:
- Delete file from File Provider you are using - e,g, MonoXFileSystemProvider
- Delete the file item entry in the SnFiles table
- Remove/Delete the relation from SnRelationship table

Regards
This content has not been rated yet. 
15993 Reputation 2214 Total posts
devmonox

devmonox

12/13/2012 10:03:11 AM
Thanks a lot. I will have to dig down little bit further regarding 3 stage deleting like you said. Before getting into complex scenario, i want to access the uploaded images. How can access so that i can show in profile when viewed?
I am uploading 800 x 400 image and i want to show on the top of profile view...

Edited:
=====
I just noticed that its give me error when i delete image from file Gallery. View the attachment. Is there any was get it fixed? Its coming only in Chrome.

Edited:13-12-2012
======
I realized that it is uploading all images in the upload folder and keeping the same file name. So if User A delete file mycover.jpg, it will be deleted eventhgouh it was used for user B as well.

This content has not been rated yet. 
52 Reputation 6 Total posts
khorvat

khorvat

12/14/2012 7:44:26 AM
We will have to review this and get back to you:
Edited:13-12-2012
======
I realized that it is uploading all images in the upload folder and keeping the same file name. So if User A delete file mycover.jpg, it will be deleted eventhgouh it was used for user B as well.

How can access so that i can show in profile when viewed?
I am uploading 800 x 400 image and i want to show on the top of profile view...
There are few ways to to this

- you can fetch the SnFile record from the database via the SnRelationship relation and just use the virtual path url stored in the record
- you can extend the GetImage Handler
etc.

Regards
This content has not been rated yet. 
15993 Reputation 2214 Total posts
devmonox

devmonox

12/14/2012 12:07:31 PM
Thanks.

Did you see the Error image i attached in last post. I realized its not related to the stuff i am doing... As soon i save profile it comes up.
This content has not been rated yet. 
52 Reputation 6 Total posts
1 2