Copied to clipboard

Flag this post as spam?

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


  • Max 144 posts 166 karma points
    Jun 11, 2012 @ 11:40
    Max
    0

    umrbaco node factory get propety NULL value check

    I have a function That prints after gettign the value form a Ultimate Picker

    umbraco.NodeFactory.Node.GetCurrent().GetProperty("backCover").Value

     

    but what if the user does nto choose a media item and saves  the node

    i want to make sur eit genrates print application even without the umbraco.NodeFactory.Node.GetCurrent().GetProperty("backCover").Value

     

    such as

    if (umbraco.NodeFactory.Node.GetCurrent().GetProperty("backCover").Value == null)
                    {
                         document.Close();


                    }
                    else
                    {
                        document.NewPage();
                        umbraco.cms.businesslogic.media.Media nm = new umbraco.cms.businesslogic.media.Media(Int32.Parse(umbraco.NodeFactory.Node.GetCurrent().GetProperty("backCover").Value));

                        string fileNameExisting = Server.MapPath(nm.getProperty("umbracoFile").Value.ToString());


                        PdfReader reader = new PdfReader(fileNameExisting);
                        PdfImportedPage page = writer.GetImportedPage(reader, 1);
                        iTextSharp.text.Image mimage = iTextSharp.text.Image.GetInstance(page);
                        document.Add(mimage);

                       
                    }

                    document.Close();

     

     

    i also tried If( umbraco.NodeFactory.Node.GetCurrent().GetProperty("backCover").Value !=null)

    but it gives this error Input string not in correct format

     

    any solutions or code samples on how i can sovle this problem

     

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jun 11, 2012 @ 18:09
    Jeroen Breuer
    0

    Is no value is entered it's probably an empty string. Try this:

    if(!string.IsNullOrEmpty(umbraco.NodeFactory.Node.GetCurrent().GetProperty("backCover").Value))

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft