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

export gridview as html without savefile dialog

3 Answers 62 Views
GridView
This is a migrated thread and some comments may be shown as answers.
loraine
Top achievements
Rank 1
loraine asked on 30 May 2011, 09:55 AM
hi!

how i have a gridview placed in a raddocument and exported into an html file. how can i export it without showing the savefile dialog?

here's my code that uses savefile dialog:
SaveFileDialog dialog = new SaveFileDialog();
dialog.DefaultExt = "*.html";
dialog.Filter = "HTML Document (*.html)|*.html";

if (dialog.ShowDialog() == true)
{
    RadDocument document = CreateDocument(rgvReportData);

    document.LayoutMode = DocumentLayoutMode.Paged;

    document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
    document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));
    document.SectionDefaultPageMargin = new Telerik.Windows.Documents.Layout.Padding(2, 2, 2, 2);
    document.SectionDefaultPageOrientation = PageOrientation.Landscape;

    HtmlFormatProvider provider = new HtmlFormatProvider();

    using (Stream output = dialog.OpenFile())
    {
        provider.Export(document, output);
    }
}

as far as i know, in order to save a file to a directory automatically, you have to convert it to byte array.
how can i do that?

3 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 30 May 2011, 01:00 PM
Hello loraine,

You cannot do this in Silverlight. It is a framework restriction that prevents unwanted access to the local file system.

All the best,
Ivan Ivanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
loraine
Top achievements
Rank 1
answered on 31 May 2011, 02:23 AM
hi!

i am running my application out-of-browser so i have an elevated permission. i was able to save images without a savefile dialog. what i did is convert the image into a byte array and store it to a specific path. i presume that i can also do this in html document since i was able to do it to an image...

regards,
Loraine
0
Accepted
Ivan Ivanov
Telerik team
answered on 31 May 2011, 01:40 PM
Hi loraine,

Please, refer to the illustrated approach:
string fileName = "C:\\Users\\iivanov\\Documents\\test.xls";
            byte[] binary;   
  
            MemoryStream ms = new MemoryStream();
            clubsGrid.Export(ms,
                     new GridViewExportOptions()
                     {
                         Format = ExportFormat.Html,
                         ShowColumnHeaders = true,
                         ShowColumnFooters = true,
                         ShowGroupFooters = false,
                     });
       
            BinaryWriter bwriter = new BinaryWriter(ms); 
            bwriter.Write(true); 
            binary = ms.ToArray(); 
            bwriter.Close(); 
            ms.Close();
                        
            using (dynamic adoCom = AutomationFactory.CreateObject("ADODB.Stream"))
            {
                adoCom.Type = 1;
                adoCom.Open();
                adoCom.Write(binary);
                adoCom.SaveToFile(fileName, 2);
            }

Pay attention that the application is not given full control over the whole local file system, but to several folders like "MyDocuments", "MyPictures" etc.

Best wishes,
Ivan Ivanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
loraine
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
loraine
Top achievements
Rank 1
Share this question
or