C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Exporting Dataset in CSV, XML,XLS in ASP.Net


Posted Date: 08 Apr 2005    Resource Type: Articles    Category: .NET Framework
Author: bripMember Level: Bronze    
Rating: 1 out of 5Points: 10




Download source files - 2 Kb

Introduction



ASP.Net and .net framework provides many ways to deal with Data , many times in web scenario , we need to export data back to user , this scenario ranges from Some custom addressbook entries to custom lists and other complex transaction details , which are a result of persistant data or dta in memory.

Background



Lots of code piece were used to export dataset into file formats,this functions can be a good way to START in this format exporting path...

Using the Code


The code contains 2 function and an enum.

the functions are

public static void ExportDataSet(DataSet dsResults , ExportFormat enExport,string strColDelim, string strRowDelim, string strFileName)

and


public static string ParseToDelim(string strText, string strRowDelim , string strColDelim)


This functions uses popular regular expressions to deal with trimming , stripping of data.

Code Snippet




public static string ParseToDelim(string strText, string strRowDelim , string strColDelim)
{
Regex objReg = new Regex(@"(>\s+<)",RegexOptions.IgnoreCase);
strText = objReg.Replace(strText,"><");
strText = strText.Replace(System.Environment.NewLine,"");
strText = strText.Replace("</td></tr><tr><td>",strRowDelim);
strText = strText.Replace("</td><td>",strColDelim);
objReg = new Regex(@"<[^>]*>",RegexOptions.IgnoreCase);
strText = objReg.Replace(strText,"");
strText = System.Web.HttpUtility.HtmlDecode(strText);
return strText;
}


Steps



Step 1



Copy this Code in a CS Class. and add it to a web project

Step 2



add a BLANK web page (with just @page directive) and call the function with required parameter in page_load

About me



I am Brijesh Pandya , a Developer in .Net , I work on area like SEO,ASP.net and Blogging

http://brip.blogspot.com
http://spaces.msn.com/members/brip/
http://groups.yahoo.com/group/itsdifferent/join



Responses

Author: tim mackey    20 May 2005Member Level: Bronze   Points : 0
hi,
this is a very helpful article, and the approach you use is the best and most efficient i have found on the Internet.
i have some null values in my database that come out as the following character: Â (looks like an A with a hat on top). i tried replacing this character with the empty string but it had no effect.
can you suggest a way to overcome this?
i appreciate any help.
tim


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: SOS from your production environment
Previous Resource: Accessing Resource File (.resx) using ResourceManagerClass
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use