Hi Rahul,
You can export RadChart as an image and you can create an html file in code behind with link to the exported image file. Unfortunately Silverlight supports only a single SaveFileDialog instance to be created in a button click event. The solution is either to create both files in a single event handler and then save them as a zip file. Another way could be to use 2 buttons - 1 for saving image and other for saving the html file like this:
string
htmlPage =
Environment.NewLine +
"<head>"
+ Environment.NewLine +
"<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" />"
+ Environment.NewLine +
"<title>Untitled 1</title>"
+ Environment.NewLine +
"</head>"
+
Environment.NewLine +
"<body>"
+ Environment.NewLine +
"<img src=\"{0}\" alt=\"RadChart\" />"
+ Environment.NewLine +
"</body>"
+ Environment.NewLine +
Environment.NewLine +
"</html>"
;
private
string
imageName;
private
void
button1_Click(
object
sender, RoutedEventArgs e)
{
SaveFileDialog sfd =
new
SaveFileDialog();
sfd.DefaultExt =
".png"
;
sfd.Filter =
"Image file|*.png"
;
//Save image
imageName =
string
.Empty;
if
(sfd.ShowDialog() ==
true
)
{
imageName = sfd.SafeFileName;
using
(Stream fs = sfd.OpenFile())
{
this
.RadChart1.ExportToImage(fs,
new
PngBitmapEncoder());
}
button1.IsEnabled =
false
;
button2.IsEnabled =
true
;
}
}
private
void
button2_Click(
object
sender, RoutedEventArgs e)
{
SaveFileDialog sfd1 =
new
SaveFileDialog();
sfd1.DefaultExt =
".html"
;
sfd1.Filter =
"HTML file|*.html"
; ;
// Save html file
if
(sfd1.ShowDialog() ==
true
)
{
using
(StreamWriter writer =
new
StreamWriter(sfd1.OpenFile()))
{
writer.Write(
string
.Format(htmlPage, imageName));
}
button1.IsEnabled =
true
;
button2.IsEnabled =
false
;
}
}
You can find in the attached file a runnable sample project that demonstrates the code above in action.
All the best,
Yavor Ivanov
the Telerik team
Browse the
videos here>> to help you get started with RadControls for Silverlight