This is a migrated thread and some comments may be shown as answers.

Images Stored In Database

4 Answers 150 Views
Rotator
This is a migrated thread and some comments may be shown as answers.
Fitz
Top achievements
Rank 1
Fitz asked on 26 Feb 2009, 12:07 PM
Hi

Is it possible to get the RadRotator control to reference images that are stored in a SQL Server 2008 database, rather than in the file system itself?

Any help or code segments would be appreciated.

Regards
Fitz

4 Answers, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 27 Feb 2009, 03:14 PM
Hi Fitz,

Yes you can achieve this by using the same approach as with local images. There is only one difference when you use images stored in DB. Instead the path ( the value of the src property of the image) of an image you need to use the path to a handler that gets the image from the database and returns it to the browser. For example instead of "/images/image1.jpg" you need to use "ImageHandler.aspx?image=image1.jpg" . In this handler you should process the image from the DB ( depending the query) and return it to the browser. The implementation of this handler is a common programming task and it is not related to the RadRotator control. You can check the following Google search for more details.

Greetings,
Fiko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
ManniAT
Top achievements
Rank 2
answered on 09 Mar 2009, 01:47 PM
By the way,

a tip how I solve this.
First of all - I hate this "handler id passing" :)

So I wrote a http handler and bound it to a "not used" extension in web.config

<add path="*.jpeg" verb="GET" type="MyApp.Namespace.JPEGHandler" validate="false" /> 
In the handler I get the filename (path) and use it as a search criteria for DB access.

    public class JPEGHandler : IHttpHandler {  
 
        public void ProcessRequest(HttpContext context) {  
            HttpResponse hR = context.Response;  
            string strFileName = Path.GetFileNameWithoutExtension(context.Request.FilePath).ToLower();  
            //you could also split the path a bit more for to address differnt tables / colums in your database  
            // /Customers/Locations/MyCust.jpeg could mean  
            // take the Location image from the customers -- where customername==MyCust  
            // OR /Employees/Portrait/Joe.jpeg  
            // takte the portrait from employees -- where employeename==Joe  
 
            //for demonstration purposes I "produce" my image instead of loading it from database  
            Bitmap bmpRet = new Bitmap(130, 130);  
            bmpRet.SetResolution(96, 96);  
            Graphics gR = Graphics.FromImage(bmpRet);  
            gR.DrawString(strFileName, SystemFonts.DefaultFont, Brushes.Red, 3, 3);  
            gR.Dispose();  
            hR.Clear();  
            //important to set the correct mime type  
            hR.ContentType = "image/jpg";  
            //cache duration depends on your DB changes  
            hR.Cache.SetExpires(DateTime.Now.AddSeconds(3));  
            hR.Cache.SetCacheability(HttpCacheability.Public);  
            hR.Cache.SetValidUntilExpires(true);  
            hR.BufferOutput = true;  
            bmpRet.Save(hR.OutputStream, ImageFormat.Jpeg);  
            bmpRet.Dispose();  
            hR.Flush();  
        }  
 
        public bool IsReusable {  
            get {  
                return false;  
            }  
        }  
    }  
 

This approach is SEO friendly out of the box.
.../Handler.ashx?ImgID=XVR33 is not that good for search engines as if you write
../Cutomers/Microsoft.jpeg

A last thing - you have to tell IIS that it should process requests to (in this case) JPEG (and ensure that check for existing file is NOT set).

And as Fiko said - getting an image from the DB hast nothing to do with RAD-(or other) controls.
Which means - you can also use such "image paths" anywhere in your app.
Things like <img src="/Customers/TomTom.jpeg"... will also work with an approach like this.

Maybe I could help a little with this idea.
Regards

Manfred
0
Fiko
Telerik team
answered on 10 Mar 2009, 02:32 PM
Hello Manfred,

Thank you for sharing this code. I believe it will be useful for other members of our community that have such task.

Sincerely yours,
Fiko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
ManniAT
Top achievements
Rank 2
answered on 10 Mar 2009, 04:46 PM
You are welcome :)

By the way - one of the reasons why I implemented this are forums.
For serveral reasons it is sometimes nice to provide "live data" in such forums.
BUT (of course) IFRAMES are normaly disabled - but most of the time you can post images.

So with a bit intelligent caching you can provide "live information" via posting an image.

A scenario I had (just to provide an example):
Our WoW guild planed a meeting.
I was involved in planing - to make things easier I made a little DB app where I stored the reservations the
the payment status and such things.

Our main communication platform is PHBB - so I had to decide if I would
a.) Maintain a website with registration and so on
OR
b.) Use the existing infrastructure (our PHBB forum)

Of course b.) was the decission. And to provide actual information I opened a thread and linked such a "jpeg image".
On my server I took the data made a simple list and provided this as image.

After closing the reservation / payment - I saved a copy of this image to disk - and changed my link in the post from XXX.jpEg to xxx.jpg.
So the final result is visible "for ever" :)

The same thing I do for "temperature logging" of my server room.
I draw the temperature lines to an image - and even with the most simple browser (mobile phone as an example) I can view the current situation in my serverroom.

This was my first project using this technology - the reason - my mobile phone did not display images when the path was not an "image path" - so ../ShowImg.aps?ID=123 did not display -- ../123.jpeg does.

Regards

Manfred
Tags
Rotator
Asked by
Fitz
Top achievements
Rank 1
Answers by
Fiko
Telerik team
ManniAT
Top achievements
Rank 2
Share this question
or