Return to Snippet

Revision: 62170
at February 6, 2013 07:31 by lmontealegre


Initial Code
using System;
using System.Collections.Generic;
using System.Text;
using VisualWebRipper;

namespace DataExport
{
    class Program
    {
        static void Main(string[] args)
        {
            WrProject project = WrProject.LoadByName("projectName");
            WrExportData data = project.OpenExportedData();
            WrExportArguments exportArgs = new WrExportArguments(data, project);
            ExportData(exportArgs);
        }

        public static bool ExportData(WrExportArguments args)
        {
            try
            {
                //First we set the SQL we'll use to insert data into the database table.      
                //The Database connection has already been set by defining a shared script       
                //database. Visual Web Ripper will automatically open and close the       
                //database connection.      
                args.Database.SetSql("insert into properties (type,fors,title,description,area) values (@type,@fors,@title,@description,@area)");
                args.Database.PrepareSql();

                //Loop htough all eth export tables
                foreach (WrExportTableDefinition table in args.ExportData.TablesDefinitions.Tables)
                {
                    //Open a data reader for the current table
                    WrExportTableReader reader = args.ExportData.GetTableReader(table.TableName);
                    try
                    {
                        //Loop though all rows in the current data table and write them to the target database.
                        while (reader.Read())
                        {
                            args.Database.SetParameterTextValue("@type",
                                reader.GetStringValue("type"));
                            args.Database.SetParameterTextValue("@fors",
                                reader.GetStringValue("fors"));
                            args.Database.SetParameterTextValue("@title",
                                reader.GetStringValue("title"));
                            args.Database.SetParameterTextValue("@description",
                                reader.GetStringValue("description"));
                            args.Database.SetParameterTextValue("@area",
                                reader.GetStringValue("area"));
                            args.Database.ExecuteNonQuery();
                        }
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
                return true;
            }
            catch (Exception exp)
            {
                args.WriteDebug(exp.Message);
                return false;
            }
        }
    }
}

Initial URL


Initial Description
The Application should load the export data for your project and then call the ExportData method.

Initial Title
Export Script - Sample1

Initial Tags


Initial Language
C#