Export Datagrid to text file for froogle feed

F

footballhead

I have a page with a datagrid that I have configured with all the
information I need to provide to froogle for listing my products on
their site. I am having trouble finding a way to successfully save the
data in this datagrid as a text file.

I am somewhat limited in that I do _NOT_ have access to code-behind.
All code I use must be inline on the ASPX and the ASCX pages. I can
create new pages if that would help.

Does anyone know of a way to export the data using only inline code on
this page? The datagrid has an id="grdResults". The code does not need
to download the text file, just save it to a folder on the site. I can
download it later.

If any of you have solutions or suggestions I would be very grateful!


Thanks,


five40
 
T

Tim_Mac

hi
although it can be easier to have code-behind, to my knowledge you can
achieve the same things with inline code. so don't worry about that.
this code below will render a datagrid into a string, which is a valid excel
document.

// get the text of the rendered datagrid
string datagridText;
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
// instantiate a datagrid
grdResults.RenderControl(htw);
datagridText = sw.ToString();
}
}

if you want a CSV format, you can adapt the code from this article:
http://tim.mackey.ie/PermaLink.aspx?guid=2ce7cfa7-8c67-478d-9bcd-7e3ee82af55f
and instead of sending the CSV string to the HttpResponse, write it to a
file.

hope this helps
tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top