Friday, November 5, 2010

IEnumerable - DataTable Export to Word / Excel / PDF / HTML

I found the codePlex Project Exporter.codeplex.com more useful for my application
where u can export the datatable List to Word / Excel / PDF / HTML.

where it worked for windows Application without an issue.
when i added it to the web application it failed. Here is the fix..
Exporter need to change in code for web and windows application. So its better to determine the type of application accessing it and access the template.
Add reference System.Web; to ExportDLL and declare a Property setter as follows.
public static bool IsWebApplication
{
get
{
try
{
System.Web.HttpContext Context = System.Web.HttpContext.Current;
if (Context != null)
return true;
}
catch { }

return false;
}
}

and in the StringTemplateGroup Check the application is web and set the Server.MapPath for PathFiles
private static StringTemplateGroup stgCollection
{
get
{
string where = @"templates\Collection";
if (IsWebApplication)
PathFiles = System.Web.HttpContext.Current.Server.MapPath("bin");

if (!string.IsNullOrEmpty(PathFiles))
{
where = Path.Combine(PathFiles, where);
}
StringTemplateGroup stg = new StringTemplateGroup("Collection", where);
stg.RegisterAttributeRenderer(typeof(string), new AdvancedStringRenderer());
stg.RegisterAttributeRenderer(typeof(DateTime), new AdvancedDateTimeRenderer());
return stg;
}
}

and here is the link

http://exporter.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=163747

No comments:

Post a Comment