How to Retrieving Image from Rich Textbox Editor in Dynamic

Posted by Community Admin on 04-Aug-2018 10:34

How to Retrieving Image from Rich Textbox Editor in Dynamic Modules Using the Module Builder API

All Replies

Posted by Community Admin on 16-Jun-2014 00:00

Hi All,

I'm Using Dynamic Modules Using the Module Builder API, I added images in Rich text box Editor ,

I'm Unable to Get Image url's in my web site.

i'm getting image tag like

<img src="[libraryprovider2][16 digit GUID]"/>

I wrote code like 

var allentries = Extensions.RetrieveCollectionOfModuleData();
var firstRow = allentries.First(x => x.GetValue<string>("uname") == "Ajay");
divdescription.InnerHTML = firstRow.GetValue("description").ToString();

Please help me, how to Get images from Rich Text box Editor.

 Thanks

Ajay

Posted by Community Admin on 18-Jun-2014 00:00

Hi Ajay,

Since you can get the GUID of the image stored in the Rich Text field, you can retrieve it using the Images API by using this guid. In general the Rich Text field returns a persisted value of type string that includes all of the markup present there. The markup consists of an img tag with its source equal to the url of your image, alt text and title equal to your image's metadata and a sfref attribute that is formed in the following way [mediatype|ProviderName]itemGuid. 

The best way for you to proceed is to trim the markup string such that you can get the GUID or URL of the image and then use it as you please. Below you can find the code I used to get the value of my RichTextField:

DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
            Type richTextType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.RichTextFieldTest.RichText");
 
            var richTextItem = dynamicModuleManager.GetDataItems(richTextType).ToList();
 
            foreach (var item in richTextItem)
            
                  if (item.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master)
                
                    var HTMLField = item.GetValue("RichText");
                
    
            


Regards,
Ivan D. Dimitrov
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 23-Jun-2014 00:00

Hi Ivan,

Thanks for Reply , I'm Doing same as Above but I Did n't Get Image URL.

here i'm adding sample video containing my code.

I'm using version 6.2 and Using multisite management  

Please Help me how to solve this.

 

Thanks 

Ajay

 

Posted by Community Admin on 23-Jun-2014 00:00

Hi Ajay,

Looks like you are almost there. The description value you get is the correct markup of the field, so you will need to cast it to string and trim the string such that only the Guid is present. From then on you can get the image by matching this Guid with the image's ID. I believe there is abundant information on trimming and substringing a string in c# available on the web.

Regards,
Ivan D. Dimitrov
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 24-Jun-2014 00:00

Hi Ivan,

I'm Having Multiple Images with Content( different for Each Row ),

How would i know start index,

Please Help me and send me sample code containing Multiple Images and static text

Thanks

Ajay

Posted by Community Admin on 24-Jun-2014 00:00

Hi Ajay,

I am afraid I cannot do that as this case is very specific to your project.

I can recommend you try and use an image field instead of inserting the images in the RichText editor. This will ease the process of you acquiring the desired images.

You can see for your self the extensive amount of markup that the Editor generates and thus it makes filtering out the images in it difficult to get hold of.

Regards,
Ivan D. Dimitrov
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 25-Jun-2014 00:00

Hi Ivan,

Thanks for Replay, 

Finally solved problem with this link

Thanks

Ajay

 

 

This thread is closed