Saving media properties Options
Dim
Posted: Tuesday, February 05, 2008 5:44:36 PM
Rank: Newbie

Joined: 2/5/2008
Posts: 3
I need to modify the properties of a media node from whithin a webservice which is written in C#. The folowing code leads to a partial success:

Code:

    [WebMethod]
    public string MakeComment(string Comment, int MediaID) {
        try
        {
            umbraco.cms.businesslogic.media.Media myMedia = new umbraco.cms.businesslogic.media.Media(MediaID);
            myMedia.getProperty("Comments").Value = Comment;
            myMedia.Save();
        }
        catch (Exception e)
        {
            return e.ToString();
        }
        return myMedia.getProperty("Comments").Value.ToString();
    }


After invoking, the new property value shows up correctly in Umbraco's media manager. However, when I try to access it with an XSLT macro, it still uses the old value. When I click the "Save" button in the manager (without modifying the value manually), the XSLT macro starts using the updated value.
I guess that I have to rebuild some part of Umbraco's cache, but I can't seem to find an appropriate function within the API.

Can anyone point me to the correct solution? :)
jesperw
Posted: Thursday, February 21, 2008 3:01:36 PM
Rank: Enthusiast

Joined: 9/6/2007
Posts: 10
Had the same problem today, until I viewed through the umbraco back end source. The problem seems to be:

When you save properties on media nodes, they are saved to the database but the xml cache is not re-created (and your xslt macros reads from the xml cache). The code that did it for me:
Code:

umbraco.cms.businesslogic.media.Media m = new umbraco.cms.businesslogic.media.Media(mediaId);
m.getProperty("TheProperty").Value = "new property value";

m.XmlGenerate(new System.Xml.XmlDocument()); // this seems to republish changes in database to the XML cache.


Cheers
/ Jesper
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.