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

[Solved] GridView export

1 Answer 123 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
mark
Top achievements
Rank 1
mark asked on 17 Aug 2009, 01:40 PM
does anyone have problem with export from GridView? I've ran online demo (as well as our code) and it seems that it truncates the output. Almost looks like stream is not flushed, although adding .Flush() does not fix the problem

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 17 Aug 2009, 02:33 PM
Hi mpytlik,

The bug in our demo is confirmed - I've added 2000 Telerik points to your account!

The correct code should be:

            if (SaveAsFileCheckBox.IsChecked == true)
            {
                SaveFileDialog dialog = new SaveFileDialog()
                {
                    DefaultExt = extension,
                    Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, selectedItem),
                    FilterIndex = 1
                };

                if (dialog.ShowDialog() == true)
                {
                    using (Stream stream = dialog.OpenFile())
                    {
                        if (extension != "xml")
                        {
                            using (StreamWriter sw = new StreamWriter(stream, Encoding.UTF8))
                            {
                                sw.Write(content);
                            }

                        }
                        else
                        {
                            Byte[] bytes = Encoding.UTF8.GetBytes(content);
                            stream.Write(bytes, 0, bytes.Length);
                        }
                        stream.Close();
                    }
                }
            }

All the best,
Vlad
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.
Tags
GridView
Asked by
mark
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or