using umbraco library to update item - URGENT, any help very welcome Options
tim
Posted: Thursday, April 05, 2007 4:11:20 PM

Rank: Addict

Joined: 2/19/2007
Posts: 825
Location: Belgium
Hi,

I Need to know how i can lookup a certain item and update it's property's..

I have an item with

name : oostende
Document Type: CentrumPage

and i want to update these properties:

xcoor
ycoor

I need to do this from a usercontrol


Greetings,


Tim

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
sjors
Posted: Thursday, April 05, 2007 4:15:57 PM

Rank: Fanatic

Joined: 7/20/2006
Posts: 408
Location: Amsterdam
tim
Posted: Thursday, April 05, 2007 4:18:12 PM

Rank: Addict

Joined: 2/19/2007
Posts: 825
Location: Belgium
I did, but the trouble starts with the first line

using umbraco.cms.businesslogic.web;

...

I think this was for an older version of umbraco

I am using 2.1.6



Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Thursday, April 05, 2007 4:22:21 PM

Rank: Addict

Joined: 2/19/2007
Posts: 825
Location: Belgium
Fixed that, going to try to update now

Greetings

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
sjors
Posted: Thursday, April 05, 2007 4:24:31 PM

Rank: Fanatic

Joined: 7/20/2006
Posts: 408
Location: Amsterdam
Try to look in an existing sample (ie autoform module).
tim
Posted: Friday, April 06, 2007 10:14:54 AM

Rank: Addict

Joined: 2/19/2007
Posts: 825
Location: Belgium
Managed to do it, don't know if i did it the recommended way, but it works.

on page load I do this:
Code:


foreach( Document tempDocument in  Document.GetRootDocuments()){
               
                if (tempDocument.HasChildren)
                {
                   
                    loopChildren(tempDocument);
                }
               
            }


Then i have this function

So i lop through every document, and if the contenttype = "CentrumPage" and the name of my document is correct

I update 2 property's and publish the document



Code:


     private void loopChildren(Document ParentDocument)
        {
            foreach (Document tempDocument in ParentDocument.Children)
            {
                if (tempDocument.ContentType.Text == "CentrumPage" && tempDocument.Text.ToLower() == Request["name"].ToString().ToLower())
                {
                 
                    Label1.Text += "Centrum " + Request["name"].ToString() + " Updated";

                    foreach (Property tempProp in tempDocument.getProperties)
                    {
                       
                        if (tempProp.PropertyType.Alias == "xcoor")
                        {
                            tempProp.Value = (int) Math.Round(Convert.ToDouble( Request["x"].ToString().Replace(".",",")), 0);
                           
                        }

                        if (tempProp.PropertyType.Alias == "ycoor")
                        {
                            tempProp.Value = (int)Math.Round(Convert.ToDouble(Request["y"].ToString().Replace(".", ",")), 0);
                           
                        }

                       
                    }
                    tempDocument.Publish(new umbraco.BusinessLogic.User(0) );

                }

                if (tempDocument.HasChildren)
                {

                    loopChildren(tempDocument);


                }

            }

        }


Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Friday, April 06, 2007 10:15:04 AM

Rank: Addict

Joined: 2/19/2007
Posts: 825
Location: Belgium
Managed to do it, don't know if i did it the recommended way, but it works.

on page load I do this:
Code:


foreach( Document tempDocument in  Document.GetRootDocuments()){
               
                if (tempDocument.HasChildren)
                {
                   
                    loopChildren(tempDocument);
                }
               
            }


Then i have this function

So i lop through every document, and if the contenttype = "CentrumPage" and the name of my document is correct

I update 2 property's and publish the document



Code:


     private void loopChildren(Document ParentDocument)
        {
            foreach (Document tempDocument in ParentDocument.Children)
            {
                if (tempDocument.ContentType.Text == "CentrumPage" && tempDocument.Text.ToLower() == Request["name"].ToString().ToLower())
                {
                 
                    Label1.Text += "Centrum " + Request["name"].ToString() + " Updated";

                    foreach (Property tempProp in tempDocument.getProperties)
                    {
                       
                        if (tempProp.PropertyType.Alias == "xcoor")
                        {
                            tempProp.Value = (int) Math.Round(Convert.ToDouble( Request["x"].ToString().Replace(".",",")), 0);
                           
                        }

                        if (tempProp.PropertyType.Alias == "ycoor")
                        {
                            tempProp.Value = (int)Math.Round(Convert.ToDouble(Request["y"].ToString().Replace(".", ",")), 0);
                           
                        }

                       
                    }
                    tempDocument.Publish(new umbraco.BusinessLogic.User(0) );

                }

                if (tempDocument.HasChildren)
                {

                    loopChildren(tempDocument);


                }

            }

        }


Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Friday, April 06, 2007 10:15:35 AM

Rank: Addict

Joined: 2/19/2007
Posts: 825
Location: Belgium
Managed to do it, don't know if i did it the recommended way, but it works.

on page load I do this:
Code:


foreach( Document tempDocument in  Document.GetRootDocuments()){
               
                if (tempDocument.HasChildren)
                {
                   
                    loopChildren(tempDocument);
                }
               
            }


Then i have this function

So i lop through every document, and if the contenttype = "CentrumPage" and the name of my document is correct

I update 2 property's and publish the document



Code:


     private void loopChildren(Document ParentDocument)
        {
            foreach (Document tempDocument in ParentDocument.Children)
            {
                if (tempDocument.ContentType.Text == "CentrumPage" && tempDocument.Text.ToLower() == Request["name"].ToString().ToLower())
                {
                 
                    Label1.Text += "Centrum " + Request["name"].ToString() + " Updated";

                    foreach (Property tempProp in tempDocument.getProperties)
                    {
                       
                        if (tempProp.PropertyType.Alias == "xcoor")
                        {
                            tempProp.Value = (int) Math.Round(Convert.ToDouble( Request["x"].ToString().Replace(".",",")), 0);
                           
                        }

                        if (tempProp.PropertyType.Alias == "ycoor")
                        {
                            tempProp.Value = (int)Math.Round(Convert.ToDouble(Request["y"].ToString().Replace(".", ",")), 0);
                           
                        }

                       
                    }
                    tempDocument.Publish(new umbraco.BusinessLogic.User(0) );

                }

                if (tempDocument.HasChildren)
                {

                    loopChildren(tempDocument);


                }

            }

        }


Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Friday, April 06, 2007 10:15:48 AM

Rank: Addict

Joined: 2/19/2007
Posts: 825
Location: Belgium
Managed to do it, don't know if i did it the recommended way, but it works.

on page load I do this:
Code:


foreach( Document tempDocument in  Document.GetRootDocuments()){
               
                if (tempDocument.HasChildren)
                {
                   
                    loopChildren(tempDocument);
                }
               
            }




Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Friday, April 06, 2007 10:16:35 AM

Rank: Addict

Joined: 2/19/2007
Posts: 825
Location: Belgium
Managed to do it, don't know if i did it the recommended way, but it works.

on page load I do this:
Code:


foreach( Document tempDocument in  Document.GetRootDocuments()){
               
                if (tempDocument.HasChildren)
                {
                   
                    loopChildren(tempDocument);
                }
               
            }


Then i have this function

So i lop through every document, and if the contenttype = "CentrumPage" and the name of my document is correct

I update 2 property's and publish the document



Code:


     private void loopChildren(Document ParentDocument)
        {
            foreach (Document tempDocument in ParentDocument.Children)
            {
                if (tempDocument.ContentType.Text == "CentrumPage" && tempDocument.Text.ToLower() == Request["name"].ToString().ToLower())
                {
                 
                    Label1.Text += "Centrum " + Request["name"].ToString() + " Updated";

                    foreach (Property tempProp in tempDocument.getProperties)
                    {
                       
                        if (tempProp.PropertyType.Alias == "xcoor")
                        {
                            tempProp.Value = (int) Math.Round(Convert.ToDouble( Request["x"].ToString().Replace(".",",")), 0);
                           
                        }

                        if (tempProp.PropertyType.Alias == "ycoor")
                        {
                            tempProp.Value = (int)Math.Round(Convert.ToDouble(Request["y"].ToString().Replace(".", ",")), 0);
                           
                        }

                       
                    }
                    tempDocument.Publish(new umbraco.BusinessLogic.User(0) );

                }

                if (tempDocument.HasChildren)
                {

                    loopChildren(tempDocument);


                }

            }

        }


Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Friday, April 06, 2007 10:17:08 AM

Rank: Addict

Joined: 2/19/2007
Posts: 825
Location: Belgium
test post , because I'm getting this error:

System.OutOfMemoryException


Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Friday, April 06, 2007 10:18:29 AM

Rank: Addict

Joined: 2/19/2007
Posts: 825
Location: Belgium
Managed to do it, don't know if i did it the recommended way, but it works.

on page load I do this:
Code:


foreach( Document tempDocument in  Document.GetRootDocuments()){
               
                if (tempDocument.HasChildren)
                {
                   
                    loopChildren(tempDocument);
                }
               
            }


Then i have this function

So i lop through every document, and if the contenttype = "CentrumPage" and the name of my document is correct

I update 2 property's and publish the document



Code:


     private void loopChildren(Document ParentDocument)
        {
            foreach (Document tempDocument in ParentDocument.Children)
            {
                if (tempDocument.ContentType.Text == "CentrumPage" && tempDocument.Text.ToLower() == Request["name"].ToString().ToLower())
                {
                 
                    Label1.Text += "Centrum " + Request["name"].ToString() + " Updated";

                    foreach (Property tempProp in tempDocument.getProperties)
                    {
                       
                        if (tempProp.PropertyType.Alias == "xcoor")
                        {
                            tempProp.Value = (int) Math.Round(Convert.ToDouble( Request["x"].ToString().Replace(".",",")), 0);
                           
                        }

                        if (tempProp.PropertyType.Alias == "ycoor")
                        {
                            tempProp.Value = (int)Math.Round(Convert.ToDouble(Request["y"].ToString().Replace(".", ",")), 0);
                           
                        }

                       
                    }
                    tempDocument.Publish(new umbraco.BusinessLogic.User(0) );

                }

                if (tempDocument.HasChildren)
                {

                    loopChildren(tempDocument);


                }

            }

        }


Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Friday, April 06, 2007 10:36:55 AM

Rank: Addict

Joined: 2/19/2007
Posts: 825
Location: Belgium
Managed to do it, don't know if i did it the recommended way, but it works.

on page load I do this:
Code:


foreach( Document tempDocument in  Document.GetRootDocuments()){
               
                if (tempDocument.HasChildren)
                {
                   
                    loopChildren(tempDocument);
                }
               
            }


Then i have this function

So i lop through every document, and if the contenttype = "CentrumPage" and the name of my document is correct

I update 2 property's and publish the document



Code:


     private void loopChildren(Document ParentDocument)
        {
            foreach (Document tempDocument in ParentDocument.Children)
            {
                if (tempDocument.ContentType.Text == "CentrumPage" && tempDocument.Text.ToLower() == Request["name"].ToString().ToLower())
                {
                 
                    Label1.Text += "Centrum " + Request["name"].ToString() + " Updated";

                    foreach (Property tempProp in tempDocument.getProperties)
                    {
                       
                        if (tempProp.PropertyType.Alias == "xcoor")
                        {
                            tempProp.Value = (int) Math.Round(Convert.ToDouble( Request["x"].ToString().Replace(".",",")), 0);
                           
                        }

                        if (tempProp.PropertyType.Alias == "ycoor")
                        {
                            tempProp.Value = (int)Math.Round(Convert.ToDouble(Request["y"].ToString().Replace(".", ",")), 0);
                           
                        }

                       
                    }
                    tempDocument.Publish(new umbraco.BusinessLogic.User(0) );

                }

                if (tempDocument.HasChildren)
                {

                    loopChildren(tempDocument);


                }

            }

        }


Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Friday, April 06, 2007 2:42:30 PM

Rank: Addict

Joined: 2/19/2007
Posts: 825
Location: Belgium
Managed to do it, don't know if i did it the recommended way, but it works.

on page load I do this:
Code:


foreach( Document tempDocument in  Document.GetRootDocuments()){
               
                if (tempDocument.HasChildren)
                {
                   
                    loopChildren(tempDocument);
                }
               
            }


Then i have this function

So i lop through every document, and if the contenttype = "CentrumPage" and the name of my document is correct

I update 2 property's and publish the document



Code:


     private void loopChildren(Document ParentDocument)
        {
            foreach (Document tempDocument in ParentDocument.Children)
            {
                if (tempDocument.ContentType.Text == "CentrumPage" && tempDocument.Text.ToLower() == Request["name"].ToString().ToLower())
                {
                 
                    Label1.Text += "Centrum " + Request["name"].ToString() + " Updated";

                    foreach (Property tempProp in tempDocument.getProperties)
                    {
                       
                        if (tempProp.PropertyType.Alias == "xcoor")
                        {
                            tempProp.Value = (int) Math.Round(Convert.ToDouble( Request["x"].ToString().Replace(".",",")), 0);
                           
                        }

                        if (tempProp.PropertyType.Alias == "ycoor")
                        {
                            tempProp.Value = (int)Math.Round(Convert.ToDouble(Request["y"].ToString().Replace(".", ",")), 0);
                           
                        }

                       
                    }
                    tempDocument.Publish(new umbraco.BusinessLogic.User(0) );

                }

                if (tempDocument.HasChildren)
                {

                    loopChildren(tempDocument);


                }

            }

        }


Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Friday, April 06, 2007 2:42:47 PM

Rank: Addict

Joined: 2/19/2007
Posts: 825
Location: Belgium
Managed to do it, don't know if i did it the recommended way, but it works.

on page load I do this:
Code:


foreach( Document tempDocument in  Document.GetRootDocuments()){
               
                if (tempDocument.HasChildren)
                {
                   
                    loopChildren(tempDocument);
                }
               
            }


Then i have this function

So i lop through every document, and if the contenttype = "CentrumPage" and the name of my document is correct

I update 2 property's and publish the document



Code:


     private void loopChildren(Document ParentDocument)
        {
            foreach (Document tempDocument in ParentDocument.Children)
            {
                if (tempDocument.ContentType.Text == "CentrumPage" && tempDocument.Text.ToLower() == Request["name"].ToString().ToLower())
                {
                 
                    Label1.Text += "Centrum " + Request["name"].ToString() + " Updated";

                    foreach (Property tempProp in tempDocument.getProperties)
                    {
                       
                        if (tempProp.PropertyType.Alias == "xcoor")
                        {
                            tempProp.Value = (int) Math.Round(Convert.ToDouble( Request["x"].ToString().Replace(".",",")), 0);
                           
                        }

                        if (tempProp.PropertyType.Alias == "ycoor")
                        {
                            tempProp.Value = (int)Math.Round(Convert.ToDouble(Request["y"].ToString().Replace(".", ",")), 0);
                           
                        }

                       
                    }
                    tempDocument.Publish(new umbraco.BusinessLogic.User(0) );

                }

                if (tempDocument.HasChildren)
                {

                    loopChildren(tempDocument);


                }

            }

        }


Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
sjors
Posted: Friday, April 06, 2007 3:24:27 PM

Rank: Fanatic

Joined: 7/20/2006
Posts: 408
Location: Amsterdam
Oh this stupid smiley bug :(
Can someone please remove the smileys? I think correct display of code is more important as some smileys ;)
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.