Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Paul Griffiths 370 posts 1021 karma points
    Feb 10, 2014 @ 21:10
    Paul Griffiths
    0

    Help using images with .net user controls

    Hi guys I'm wondering if you can help me again? I'm creating a website that allows users to enter values into a .net user control and when they press the save button it populates and saves and publishes a node in the umbraco back office. Once the user revisits the page to perform updates the fields in the .net user control are populated with those being stored in the node.

    So far I have managed to complete this with any text values such as name, email etc but i am unsure how to achieve it with images.

    The code i used for the text box values is as follows

    Node currentPage = Node.GetCurrent(); // Take the values from the current umbraco node and display them to the user so they can be edited
    
                txtName.Text = currentPage.GetProperty("Name").Value;
                txtShortDescription.Text = currentPage.GetProperty("ShortDescription").Value;
                txtFullDescription.Text = currentPage.GetProperty("FullDescription").Value;
    
    
    // Take the values edited by the user and update the node in the umbraco backend
    // Get the Document object via the nodefactory
                Document currentPage = new Document(Node.GetCurrent().Id);
    
            // Update the name of the node (text property)
            currentPage.Text = txtName.Text;      
    
            currentPage.getProperty("Name").Value = txtName.Text;
            currentPage.getProperty("ShortDescription").Value = txtShortDescription.Text;
            currentPage.getProperty("FullDescription").Value = txtFullDescription.Text;
    

    Like i said this all works perfect but im really struggling with working out how to allow the user to upload an image using a file upload control, store it in the node and when the user revisits the page, when the user control renders it pulls in the image that is stored in the node.

    Any help would be great. I hope my explanation is clear.

    Thanks

    Paul

  • Per Ploug 865 posts 3491 karma points MVP admin
    Feb 11, 2014 @ 11:50
    Per Ploug
    1

    This is the old nodefactory api right?

    If I remember correctly, then you can add a upload control to the user control, that will give you a HttpPostedFile object, which you can then set on a property like:

    currentPage.getProperty("file").Value = fileObj;
    

    If the datatype is = upload it should save the file on disk and save the path on the property

  • Per Ploug 865 posts 3491 karma points MVP admin
    Feb 11, 2014 @ 11:53
    Per Ploug
    1

    If that doesnt work, then I'm positive that the new contentService does support this with SetValue(httppostedfile):

    http://our.umbraco.org/documentation/Reference/Management-v6/Models/Content#SetValue(stringpropertyTypeAliasobjectvalue)

  • Paul Griffiths 370 posts 1021 karma points
    Feb 11, 2014 @ 14:23
    Paul Griffiths
    0

    Hi Per,

    Thanks for your response ;)

    Yes that is correct i am currently using the old node factory API and the data type is set on the property is upload. The version of umbraco that I am, using is v6.1.6.

    I'm wondering if you could elaborate further with regards to the httpPostedFile object and how I would use it? I'm fairly new to extending umbraco api through the use of .net user controls. I currently have a fileupload control on my user control called fileUploadVenueImage.

    here is my code

                    //venue Information
                txtName.Text = currentPage.GetProperty("Name").Value;
                txtShortDescription.Text = currentPage.GetProperty("ShortDescription").Value;
                txtFullDescription.Text = currentPage.GetProperty("FullDescription").Value;
    
                FileUploadVenueImage.FileContent = currentPage.GetProperty("venueImage").Value; // How do I treat this as fileObj?
    

    Thanks and sorry if the answer is obvious.

    Paul

  • Paul Griffiths 370 posts 1021 karma points
    Feb 11, 2014 @ 19:38
    Paul Griffiths
    0

    Hi guys still struggling with this uploading image query so any suggestions would be gratefully appreciated. The line of code below allows the user to upload an image via the user control and it updates the venue image property (datatype upload) with the file name of the image but doesnt write to the media folder. once it has been uploaded and it looks like this in the backoffice

    currentPage.getProperty("venueImage").Value = FileUploadVenueImage.PostedFile.FileName;
    

    enter image description here

    However, if you upload an image via the backend it looks like this and it writes to the media folder

    enter image description here

    I really need a method to update the backend property with the contents of what the user has uploaded (not just the name) via the user control

    Any suggestions?

  • Paul Griffiths 370 posts 1021 karma points
    Feb 11, 2014 @ 20:09
    Paul Griffiths
    1

    Just cracked it by simply removing the .filename so my code now looks like this

    currentPage.getProperty("venueImage").Value = FileUploadVenueImage.PostedFile;
    

    What a dunce lol :) happy now tho!!

Please Sign in or register to post replies

Write your reply to:

Draft