private void ExecuteDataExport(ActionArgs args, ActionResult result)
        {
            if (!(String.IsNullOrEmpty(args.CommandArgument)))
            {
                string[] arguments = args.CommandArgument.Split(',');
                if (arguments.Length > 0)
                {
                    bool sameController = (args.Controller == arguments[0]);
                    args.Controller = arguments[0];
                    if (arguments.Length == 1)
                    {
                        args.View = "grid1";
                    }
                    else
                    {
                        args.View = arguments[1];
                    }
                    if (sameController)
                    {
                        args.SortExpression = null;
                    }
                    SelectView(args.Controller, args.View);
                }
            }
            PageRequest request = new PageRequest(-1, -1, null, null);

            request.SortExpression = args.SortExpression;
            request.Filter         = args.Filter;
            request.ContextKey     = null;
            request.PageIndex      = 0;
            request.PageSize       = Int32.MaxValue;
            request.View           = args.View;
            if (args.CommandName.EndsWith("Template"))
            {
                request.PageSize = 0;
                args.CommandName = "ExportCsv";
            }
            // store export data to a temporary file
            string       fileName = Path.GetTempFileName();
            StreamWriter writer   = File.CreateText(fileName);

            try
            {
                ViewPage page = new ViewPage(request);
                page.ApplyDataFilter(_config.CreateDataFilter(), args.Controller, args.View, null, null, null);
                if (_serverRules == null)
                {
                    _serverRules = _config.CreateBusinessRules();
                    if (_serverRules == null)
                    {
                        _serverRules = CreateBusinessRules();
                    }
                }
                _serverRules.Page = page;
                _serverRules.ExecuteServerRules(request, ActionPhase.Before);
                using (DbConnection connection = CreateConnection())
                {
                    DbCommand selectCommand = CreateCommand(connection);
                    if ((selectCommand == null) && _serverRules.EnableResultSet)
                    {
                        PopulatePageFields(page);
                        EnsurePageFields(page, null);
                    }
                    ConfigureCommand(selectCommand, page, CommandConfigurationType.Select, null);
                    DbDataReader reader = ExecuteResultSetReader(page);
                    if (reader == null)
                    {
                        reader = selectCommand.ExecuteReader();
                    }
                    if (args.CommandName.EndsWith("Csv"))
                    {
                        ExportDataAsCsv(page, reader, writer);
                    }
                    if (args.CommandName.EndsWith("Rss"))
                    {
                        ExportDataAsRss(page, reader, writer);
                    }
                    if (args.CommandName.EndsWith("Rowset"))
                    {
                        ExportDataAsRowset(page, reader, writer);
                    }
                    reader.Close();
                }
                _serverRules.ExecuteServerRules(request, ActionPhase.After);
            }
            finally
            {
                writer.Close();
            }
            result.Values.Add(new FieldValue("FileName", null, fileName));
        }