?
Solved

ASP.NET - Using a Thumbnail (ashx) to display an image on an Image Control inside a Grid

Posted on 2009-12-28
23
Medium Priority
?
1,081 Views
Last Modified: 2013-11-08
Hi experts,

I am using a thumbnail (ashx) to display an image on an image control inside a grid. I am using the following line.

ImageUrl='<%# "../../" & DataBinder.Eval(Container.DataItem, "product_image") %>'

This line works fine, however, if I send the grid html by email to all users, they receive it but dont receive the image. I tried replacing that line of code with the following, but it didnt work. It even stopped showing the image in the grid itself:

ImageUrl='<%#Server.MapPath("") + "/" + DataBinder.Eval(Container.DataItem, "product_image")%>'

What would be the problem? Is it the thumbnail itself, or the path or what exactly?
0
Comment
Question by:feesu
  • 10
  • 10
21 Comments
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 26133622
You must use the full URI, append "http://www.yoursite.com/" + Eval("product_image")

Something like that.
0
 

Author Comment

by:feesu
ID: 26134678
jorge,

1- Will this work with a thumbnail?
2- If I manually write the full URI how would I run it on my test environment?

Thanks,
0
 
LVL 3

Expert Comment

by:KinjalKumar Patel
ID: 26134710
Jorge,

For the test environment you can have some sort of enum created within the application that helps you to identify globally in your application that from which domain you are running the application. Depending on the domain the URL needs to be set.

Hope this may help you.

Thanks
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Expert Comment

by:jorge_toriz
ID: 26139607
This will work with your thumbnail too.

I wrote "you must use the full URI" because you asked why the HTML doesn't work when you send it to the people you want, and without a full URI won't work, but, if you want to see your pics only in your page you shouldn't append the full URI.
0
 

Author Comment

by:feesu
ID: 26146728
jorge,

I want this to work on the live website plus on my development PC. Is that possible?
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 26146975
Yes, take out my comment about appending your full URI, just use the Eval function to get you image name and thats all, I work in this way to show images in the development and production state.
0
 

Author Comment

by:feesu
ID: 26147007
You mean not to use the thumbnail anymore?
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 26351446
I would use something like this:

ImageUrl='<%# ResolveClientUrl("~/imgProducts/") + Eval("product_image").ToString().Replace(".jpg", "_thumbnail.jpg") %>'

I suppose that your product has a thumbnail with the same name but with a postfix "_thumbnail"
0
 

Author Comment

by:feesu
ID: 26365780
jorge,

My code at design time looks like:

--------------------------------------------------------------------------------------------------------------------------------
<rad:GridTemplateColumn Groupable="False" UniqueName="ProductImage" HeaderText="IMAGE">
                    <ItemTemplate>
                        <asp:Image
                            ID="ShoppingImg" runat="server" Height="25"
                            ImageUrl='<%# "../../" + DataBinder.Eval(Container.DataItem, "product_image")%>'
                           
                            Width="25" />
                       
                    </ItemTemplate>
                    <HeaderStyle Width="30px" />
                    <ItemStyle Height="36px" HorizontalAlign="Center" VerticalAlign="Middle" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" Wrap="True" />
                </rad:GridTemplateColumn>
--------------------------------------------------------------------------------------------------------------------------------





And at run-time, this is how it looked like:

--------------------------------------------------------------------------------------------------------------------------------
<img id="ctl13_gridShoppingCart_ctl01_ctl04_ShoppingImg" src="DesktopModules/Products/Thumb.ashx?ImgPath=Files\Products\pPOLO2-6714648_standard_v330.jpg&amp;MaxHeight=250&amp;MaxWidth=230" style="height:25px;width:25px;border-width:0px;" />
--------------------------------------------------------------------------------------------------------------------------------
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 26365869
And?, what do you get?, first of all the imgPath its wrong, you must use "/", but leaving this out... what do you get?

I would prefer to store in the database the value "pPOLO2-6714648_standard_v330.jpg", the width and the height in separated columns to build up the right path at runtime with the RowDataBound event.
0
 

Author Comment

by:feesu
ID: 26365910
1- I get the image properly at runtime, but when I send the html by email, it shows "X" instead of the image.
2- I am using thumbs to pass the height/width parameters at rum time because I am using the images in different places with different sizes, I cannot save all these sizes inside the database. In order to do that I will have to do a major change to my structure.

What exactly is my problem to show the image on the recipient's email? What do I need to chage?
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 26373940
Before "DesktopModules/Products/Thumb.aspx" concatenate the full URL of that handler, like:

"http://www.mysample.com/DesktopModules/Products/Thumb.aspx"
0
 

Author Comment

by:feesu
ID: 26376051
Great, how can I do that by code, taking into account that I don't want to hard code the full URL because I want the project to work properly on the development machine as well?
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 26382884
With Request.Url.Host you get the domain name, then add "http://" before that
0
 

Author Comment

by:feesu
ID: 26385074
This is my image line in the aspx, I think I did something wrong because the image stopped showing:

<asp:Image ID="ShoppingImg" runat="server" Height="25"
ImageUrl='<%# "http://" + Request.Url.Host + "/" + DataBinder.Eval(Container.DataItem, "product_image")%>'
Width="25" />
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 26388627
In your development environment the Request.Url.Host shows "localhost:port" but it will never give you the folder where your application is running, then in the development machine you won't see your image.

Other thing that you can do is create a protected property in your page that returns the Request.Url.Host when is in published but when is in development will return your "localhost:port/App" path.
0
 

Author Comment

by:feesu
ID: 26389791
Well localhost:port will be enough, but this is not happening. It is showing localhost only without the port!
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 26390749
Append the port with the Request.Url.Port property
0
 

Author Comment

by:feesu
ID: 26423124
I did that. But still facing a problem. The image is not showing. Let me check if there is something else that needs to be changed.
0
 

Author Comment

by:feesu
ID: 26434283
I was not able to find anything.
I deployed the site and placed the order, and received the email. The email image source is as below:

http://<domain name>:80//DesktopModules/Products/Thumb.ashx?ImgPath=Files/Products/p758_DSC_4009.jpg&amp;MaxHeight=250&amp;MaxWidth=230

This is as per your recommendation, it is not working!
0
 
LVL 15

Accepted Solution

by:
jorge_toriz earned 2000 total points
ID: 26463934
You have a double slash after the port: "http://<domain name>:80//", remove one.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question