Umbraco: How to get and Set Document Property value in by c#.

In Umbraco we can set and get document type property value by c#. For doing this we need to get content or node id. Find below code that will use to get Umbraco property value in code behind file.

First Reference : umbraco.BusinessLogic, using umbraco.cms.businesslogic.web

// Create Document type object

Document docMfsFeedSettings = new Document(nodeId);

Here nodeId is the id of content or node.

String testValue;

testValue = docMfsFeedSettings.getProperty(“feedItemWidth”).Value.ToString()  // Get the property value.

docMfsFeedSettings.getProperty(“feedItemWidth”).Value = “Some Value”;  // Set the property value.

“feedItemWidth” : Is property type alias name which value we want to retrieve.

Another Umbraco Article

About these ads

6 thoughts on “Umbraco: How to get and Set Document Property value in by c#.

  1. ok after setting the value we must publish it as bellox:
    // After modifying the document, prepare it for publishing
    docMfsFeedSettings.Publish(new umbraco.BusinessLogic.User(0));
    umbraco.library.UpdateDocumentCache(docMfsFeedSettings.Id);

    • Basically it’s not needed after all setting the value you have to publish your document or content node…for keeping serialize data in data base.
      In this post http://nishantwork.wordpress.com/2012/11/21/c-how-to-serialize-json-array-data-by-c-on-server-side/
      I haven’t used docMfsFeedSettings.Publish(new umbraco.BusinessLogic.User(0));

      But In case you want to store another information or perform some logic other then event related to umbraco publish in that case you have to publish , and In case you have added some button for custom data type and doing post back in that case it will necessary …

    • @Bedoui
      According to umbraco documentation:

      If you don’t Publishing a document

      To push content changes into the website xml cache, documents need to be published after the changes have been made. This is a 2 step process as the layer handling the database transactions (umbraco.cms.businesslogic.web.document) is unaware of the layer handling the runtime and the website xml cache (umbraco.presentation.nodefactory)

      Therefore you first have to fetch the document you need, mark it ready for publishing, and then afterwards tell the runtime to update the cache for that specific item.

      Using:
      using umbraco.cms.businesslogic.web;

      Publishing:

      //Get the document by it's ID
      Document d = new Document(1234);
      
      //Mark it ready for publishing
      d.Publish(new umbraco.BusinessLogic.User(0));
      
      //Tell the runtime to update the document cache
      umbraco.library.UpdateDocumentCache(d.Id);
      
      
      
  2. Pingback: Umbraco: How to Create Custom data type in umbraco using c#. | [Code Destination]

  3. Pingback: Create your first Rss Feed Burner in umbraco | [Code Destination]

  4. Pingback: Install umbraco manually. | [Code Destination]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s