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

How to export data from Context Menu to a text file

1 Answer 376 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Doug
Top achievements
Rank 1
Doug asked on 21 Sep 2017, 01:06 PM

I am showing a RadTreeView on my page and it has a context menu associated with each node.  When you right click on any node, an option is displayed called "Export".  This export will run a stored procedure and bring data from the database.  I want to export this date to a .txt file.  This is enforced by my business requirements so exporting it to Excel or PDF is not an option!!  I also need to be able to prompt the user for location of where they want to save this file and what they want to name it.  Does telerik have any controls that will help me accomplish these tasks?  I have looked into the ClientExportManager and the export functionalities of the RadGrid and TreeList, but nothing exports data to text file that I can see.

 

thanks

 

doug

1 Answer, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 26 Sep 2017, 09:08 AM
Hello Doug,

The export to a Text file should be implemented manually.

Here is a sample implementation you could use as a starting point in your application.

<telerik:RadButton runat="server" ID="RadButton1" Text="Export to .txt" OnClick="RadButton1_Click"/>
protected void RadButton1_Click(object sender, EventArgs e)
{
    var filename = "my filename.txt";
 
    // create your file on the fly.
    var txtBuilder = new StringBuilder();
    for (int n = 0; n <= 20; n = n + 2)
    {
        txtBuilder.AppendLine(n.ToString());
    }
 
    // make it as a stream
    var txtContent = txtBuilder.ToString();
    var txtStream = new MemoryStream(Encoding.UTF8.GetBytes(txtContent));
 
    // send it to client
    Response.ClearHeaders();
    Response.ClearContent();
    Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
    Response.AddHeader("Content-Length", txtStream.Length.ToString());
    Response.ContentType = "text/plain";
    Response.Flush();
    Response.BinaryWrite(txtStream.ToArray());
    Response.End();
}

Regards,
Peter Milchev
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
TreeView
Asked by
Doug
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Share this question
or