views:

166

answers:

2

I have an Asp.Net page containing one grid and an image. The image is a google charts chart and its urls is around 1600 characters. I out together an .htm file containing the grid and the image. For the grid I use RenderControl to get its html code, and for the image, I just add an img html tag and assing the url to its src. I then send this .htm file as an email attachment.

My problem is that when you try to open the attached file, you see everything ok except the image (it doesn't show anything and when you look at the source code for the page, the img tag doesn't show any src whatsoever - it just shows < img > (without the spaces). If you open the file after you save it to disk, then it all works fine and you see the actual img src. Why???

Here's my html header:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><META http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>

And here's the image:

<img src="http://chart.apis.google.com/chart?chd=t:0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,420.95,0.00,2725.25,0.00,0.00,0.00,0.00,5036.96,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,47.82|0.0000,7.97,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,4.98,1.99,2.24,0.00,0.00,0.00,0.00,0.00,0.00,0.00,1.99,1.99|0.5100,34.04,0.00,0.00,0.00,0.00,0.00,0.00,1.00,0.00,0.00,0.00,0.00,0.00,0.00,36.77,18.01,18.26,0.00,0.00,0.00,0.00,0.00,8.99,0.00,20.06,14.01|0,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,2.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,4.00|3.0000,0.00,0.00,0.00,0.00,0.00,0.00,0.00,46.98,0.00,257.91,113.25,0.00,0.00,0.00,1.00,24.99,29.99,0.00,0.00,0.00,0.00,0.00,0.00,0.00,60.00,123.92|0,0.00,0.00,0.00,0.00,0.00,0.00,0.00,45.00,0.00,0.00,0.00,0.00,0.00,0.00,20.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,84.00|0,55.99,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,65.99&amp;chdl=Type 1|Type 2|Type 3|Type 4|Type 5|Type 6|Type 7&chco=000000,CD7F32,A62A2A,0000FF,00FF00,FF6EC7,A8A8A8&chds=0,5037&chxl=0:|6/22|6/23|6/24|6/25|6/26|6/27|6/28|6/29|6/30|7/1|7/2|7/3|7/4|7/5|7/6|7/7|7/8|7/9|7/10|7/11|7/12|7/13|7/14|7/15|7/16|7/17|7/18|1:|0|503|1006|1509|2012|2515|3018|3521|4024|4527|5037|2:|Days|3:|Amount ($)&chls=3,1,0|3,1,0|3,1,0|3,1,0|3,1,0|3,1,0|3,1,0&chm=o,990066,0,-1,6.0|o,990066,1,-1,6.0|o,990066,2,-1,6.0|o,990066,3,-1,6.0|o,990066,4,-1,6.0|o,990066,5,-1,6.0|o,990066,6,-1,6.0&chg=3.85,0&cht=lc&chs=900x300&chxt=x,y,r,t"/>

If the problem is the size of the URL, what are my choices, short of building a pdf file and attaching it? It seems that an html file is all I need and I would like to keep it simple.

+1  A: 

You could definitely be seeing a long URL problem. That happened to me when I was using Google Charts API (albeit in Rails rather than ASP.NET). I never could find the exact URL size that started to cause trouble, but some people reported troubles starting at 1024.

Google provides a couple of different encoding types you can use on the input data to shrink it, but using anything other than text encoding (what you are doing) will disable your ability to scale the data, if you care about that.

If you cannot scale the data, you may get some ugly graphs if the data stays at the maximum for long stretches or if you want to overlay two graphs with different scales.

See data formats from Google Chart API Docs

cgyDeveloper
Thanks cgyDeveloper. I really need the scaling in this case.I believe if I got the stream of the image, attached an actual .png to the email and referenced the image in the html, it should work right?
Gustavo Cavalcanti
@Gustavo, I don't think that will work until you save the files to disk.
Phil
A: 

If the GET is too long you could use a POST instead you'll have a 16k limit which is more than enough. I've used the code below to generate your chart and it worked. So yes I guess you could use the post and attach that to the email. Perhaps the problem with using GET is an issue with the email client configured to not opening image files, have you tested it in other clients?

<form action='http://chart.apis.google.com/chart' method='POST' id='post_form'>
<input type="hidden" name="cht" value="lc"  />
<input type="hidden" name="chtt" value="Demo chart"  />
<input type="hidden" name="chg" value="3.85,0" />
<input type='hidden' name='chs' value='900x300' />
<input type="hidden" name="chxt" value="x,y,r,t" />
<input type="hidden" name="chds" value="0,5037" />
<input type="hidden" name="chxl" value="0:|6/22|6/23|6/24|6/25|6/26|6/27|6/28|6/29|6/30|7/1|7/2|7/3|7/4|7/5|7/6|7/7|7/8|7/9|7/10|7/11|7/12|7/13|7/14|7/15|7/16|7/17|7/18|1:|0|503|1006|1509|2012|2515|3018|3521|4024|4527|5037|2:|Days|3:|Amount ($)" />
<input type="hidden" name="chls" value="3,1,0|3,1,0|3,1,0|3,1,0|3,1,0|3,1,0|3,1,0" />
<input type="hidden" name="chm" value="o,990066,0,-1,6.0|o,990066,1,-1,6.0|o,990066,2,-1,6.0|o,990066,3,-1,6.0|o,990066,4,-1,6.0|o,990066,5,-1,6.0|o,990066,6,-1,6.0" />
<input type="hidden" name="chco" value="000000,CD7F32,A62A2A,0000FF,00FF00,FF6EC7,A8A8A8" />
<input type="hidden" name="chdl" value="Type 1|Type 2|Type 3|Type 4|Type 5|Type 6|Type 7" />
<input type='hidden' name='chd' value='t:0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,420.95,0.00,2725.25,0.00,0.00,0.00,0.00,5036.96,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,47.82|0.0000,7.97,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,4.98,1.99,2.24,0.00,0.00,0.00,0.00,0.00,0.00,0.00,1.99,1.99|0.5100,34.04,0.00,0.00,0.00,0.00,0.00,0.00,1.00,0.00,0.00,0.00,0.00,0.00,0.00,36.77,18.01,18.26,0.00,0.00,0.00,0.00,0.00,8.99,0.00,20.06,14.01|0,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,2.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,4.00|3.0000,0.00,0.00,0.00,0.00,0.00,0.00,0.00,46.98,0.00,257.91,113.25,0.00,0.00,0.00,1.00,24.99,29.99,0.00,0.00,0.00,0.00,0.00,0.00,0.00,60.00,123.92|0,0.00,0.00,0.00,0.00,0.00,0.00,0.00,45.00,0.00,0.00,0.00,0.00,0.00,0.00,20.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,84.00|0,55.99,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,65.99'/>
<input type="submit"  />

Phil