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

[Solved] Grid export to files problem

1 Answer 89 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.
D Pankiw
Top achievements
Rank 1
D Pankiw asked on 23 Sep 2009, 05:21 PM
I have used the code provided in your demo (http://demos.telerik.com/silverlight/#GridView/Exporting) and also had to use code in one forum post (http://www.telerik.com/community/forums/silverlight/gridview/radgridview-exporting-to-excel-and-pdf.aspx#832033) and eventually I got the 4 exports to work via the open in a new window method.  My problem is the export to file -- CSV, XLS and DOC file types all get created, but with file size of zero (no errors are encountered).  The XML (ExcelML) export works fine.  I see that the code is the same for the 3 exports that don't work and different from the export that does work.  I have downloaded the Export sample project you provided (in the 2nd url above), but it doesn't implement the save to file method. 

Thanks!


Here is the code (again, copied from your demo): 

 

If dialog.ShowDialog() = True Then  
    Using stream As Stream = dialog.OpenFile()  
        If extension <> "xml" Then  
Dim sw As New StreamWriter(stream, Encoding.UTF8)  
            sw.Write(content)  
        Else  
Dim bytes As [Byte]() = Encoding.UTF8.GetBytes(content)  
            stream.Write(bytes, 0, bytes.Length)  
        End If  
        stream.Close()  
    End Using  
End If 


 

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 24 Sep 2009, 12:47 PM
Hi D Pankiw,

Good catch - definitely our mistake!

this code:
...
Dim sw As New StreamWriter(stream, Encoding.UTF8)
sw.Write(content)
...
should be:
...
Using sw As New StreamWriter(stream, Encoding.UTF8)
   sw.Write(content)
End Using
...

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
D Pankiw
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or