Quantcast
Channel: C1 CMS Foundation - Open Source on .NET
Viewing all articles
Browse latest Browse all 2540

New Post: How to update the Image Title and Description from code?

$
0
0
Hi all,

I am working in a page to allow users update the images attributes, but I have the follow error in this line:
c.Update<IMediaFile>(image);
The error is:
An exception of type 'System.InvalidOperationException' occurred in Composite.dll but was not handled in user code

Additional information: The type 'Composite.Plugins.Data.DataProviders.VirtualImageFileProvider.VirtualImageFile' is missing the attribute 
And here is the code:
using (var c = new DataConnection(PublicationScope.Published))
{

    // Get the media folder for this entity
    var folder = c.Get<IMediaFileFolder>().SingleOrDefault(f => f.KeyPath == myEntity.MyImageGalery);
    if (folder != null)
    {
        // Get all images in folder 
        var images = c.Get<IImageFile>().Where(i => i.FolderPath == folder.Path);
                    
        // Now try to update my image when i found it.
        foreach (var image in images)
        {
            if (image.Id == myImageToUpdateId)
            {
                image.Title = "New title";
                image.Description = "New description";

                 // Here I face the error :(
                c.Update<IMediaFile>(image);
            }
        }
    }
}

Viewing all articles
Browse latest Browse all 2540

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>