+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / upload photo - front end control - manage user

upload photo - front end control - manage user

9 posts, 1 answered
  1. Mark
    Mark avatar
    86 posts
    Registered:
    08 Feb 2010
    12 Aug 2010
    Link to this post
    I have an intranet that i want the intranet user (frontend) to be able to manage their profile

    Part of this is uploading an image of themselves
    I need a simple select photo on your hard drive, and it will upload to a specific folder or library (specified by me)

    does this code already exist anywhere?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Aug 2010
    Link to this post
    Hi Markus,

    You can use RadUpload control. There are built in selectors that use RadUpload, but generally the image is added to Images and Documents module. Below is a sample code of ButtonSelector that can be used to pick an image from the file system and upload it to Images and Documents module library

    <%@ Register TagPrefix="cc2" Namespace="Telerik.Libraries.WebControls" Assembly="Telerik.Libraries" %>
      
    <asp:Image ID="Photo" runat="server" ></asp:Image>
    <cc2:ButtonSelector ID="ButtonSelector1" WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/ImageEditorDialog.aspx" AssociatedControls="Photo" ItemTemplatePath="~/Sitefinity/Admin/CmsAdmin/ButtonSelector.ascx" runat="server" cssclass="changePhotoSelector" ButtonText="Upload Photo" />


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Mark
    Mark avatar
    86 posts
    Registered:
    08 Feb 2010
    12 Aug 2010
    Link to this post
    Thanks thats  great and 90% there!

    however, the front end user have too much access when choosing to upload a file
    I just want them to select a file on their computer, and upload it to a place i've specified

    i.e. all they see is select file, and upload button
    how would i do that?

    Thanks
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Aug 2010
    Link to this post
    Hi Markus,

    Then use the native RadUpload control and create a content item using our API. This will disable all other dialogs and options, so the user will have limited access

    sample code

    foreach (Telerik.Web.UI.UploadedFile file in RadUpload1.UploadedFiles)
    {
       // you can save the file to the file system first
       file.SaveAs("c:\\uploaded files\\" + file.GetName(), true);
    }
     
    var libraryManager = new Telerik.Libraries.LibraryManager();
    // get library by specified Name
    var- parentLibrary = libraryManager.GetLibrary("UserPhoto");
    // create an image content item
    var  testContent = libraryManager.CreateContent("image/jpeg");
    // specify parent library the image will belong to
    testContent.ParentID = parentLibrary.ID;
    //get the first uploaded file
    Telerik.Web.UI.UploadedFile firstFile = RadUpload1.UploadedFiles[0];
    byte[] buffer = new byte[firstFile.InputStream.Length];
    long position = 0;
    int currentByte = firstFile.InputStream.ReadByte();
    while (currentByte != -1)
    {
       buffer[position++] = (byte)currentByte;
       currentByte = firstFile.InputStream.ReadByte();
    }
    Telerik.Cms.Engine.IContent content = null;
    // upload the file
    try
    {
       content = libraryManager.UploadFile(buffer,
       firstFile.GetNameWithoutExtension(),
       firstFile.GetExtension(),
       firstFile.ContentType,
       firstFile.ContentLength,
       parentLibrary);
    }
    catch (ArgumentException ex)
    {
       Response.Write("There is an exception");
    }
    // save the image as a content of the file
    testContent.Content = buffer;


    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  5. Mark
    Mark avatar
    86 posts
    Registered:
    08 Feb 2010
    12 Aug 2010
    Link to this post
    Thanks

    Its adding the file in the correct folder, however, its failing on this line

    testContent.ParentID = parentLibrary.ID;


    all i need to do is update the user profile with the new image, i dont need to add it to the libraries section

    which bit of the code should i use for this?
    Thanks
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Aug 2010
    Link to this post
    Hi Markus,

    You have to get user that is being modified and pass its name to ProfileBase class. Then call SetPropertyValue method to update the Photo property.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Mark
    Mark avatar
    86 posts
    Registered:
    08 Feb 2010
    24 Mar 2011
    Link to this post
    Hi Ivan

    I've implelemted this and it works but i need to get 2 things working (could you provide the code please)

    1. setting photo
    (what code do i use)

    Profile.Photo = ???

    2. setting the photo after the upload
    <asp:Image ID="Photo" runat="server" ></asp:Image>

    Thanks

     

  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Mar 2011
    Link to this post
    Hello Markus,

    You can use GetPropertyValue method to get the value of your profile. To set some value use SetPropertyValue.

    All the best,
    Ivan Dimitrov
    the Telerik team
  9. Mark
    Mark avatar
    86 posts
    Registered:
    08 Feb 2010
    29 Mar 2011
    Link to this post
    Thanks Ivan!!
    I used the following code to get it working

    Profile.SetPropertyValue("Photo", "~/Libraries/UserPhotos/" + Profile.UserName + firstFile.GetExtension().ToLower());

Register for webinar
9 posts, 1 answered