Mono Support How to add additional picture in user profile? 

Viewed 34318 time(s), 11 post(s), 12/11/2012 4:55:48 PM - by devmonox
12/11/2012 4:55:48 PM
52 Reputation 6 Total posts

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.

1
12/12/2012 8:34:07 AM
15993 Reputation 2214 Total posts

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

2
12/12/2012 9:53:37 AM
52 Reputation 6 Total posts

Thanks for quick response. I will go with modules approach as that seems to work for me without structural changes of database.

3
12/12/2012 10:12:15 AM
15993 Reputation 2214 Total posts

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

4
12/12/2012 11:26:30 AM
52 Reputation 6 Total posts

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: }

5
12/12/2012 12:05:20 PM
52 Reputation 6 Total posts

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?


6
12/12/2012 12:21:37 PM
15993 Reputation 2214 Total posts

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

7
12/13/2012 10:03:11 AM
52 Reputation 6 Total posts

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.

8
12/14/2012 7:44:26 AM
15993 Reputation 2214 Total posts

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

9
12/14/2012 12:07:31 PM
52 Reputation 6 Total posts

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.

10
1 2
This is a demo site for MonoX. Please visit Mono Software for more info.