Export Script - Sample1


/ Published in: C#
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using VisualWebRipper;
  5.  
  6. namespace DataExport
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. WrProject project = WrProject.LoadByName("projectName");
  13. WrExportData data = project.OpenExportedData();
  14. WrExportArguments exportArgs = new WrExportArguments(data, project);
  15. ExportData(exportArgs);
  16. }
  17.  
  18. public static bool ExportData(WrExportArguments args)
  19. {
  20. try
  21. {
  22. //First we set the SQL we'll use to insert data into the database table.
  23. //The Database connection has already been set by defining a shared script
  24. //database. Visual Web Ripper will automatically open and close the
  25. //database connection.
  26. args.Database.SetSql("insert into properties (type,fors,title,description,area) values (@type,@fors,@title,@description,@area)");
  27. args.Database.PrepareSql();
  28.  
  29. //Loop htough all eth export tables
  30. foreach (WrExportTableDefinition table in args.ExportData.TablesDefinitions.Tables)
  31. {
  32. //Open a data reader for the current table
  33. WrExportTableReader reader = args.ExportData.GetTableReader(table.TableName);
  34. try
  35. {
  36. //Loop though all rows in the current data table and write them to the target database.
  37. while (reader.Read())
  38. {
  39. args.Database.SetParameterTextValue("@type",
  40. reader.GetStringValue("type"));
  41. args.Database.SetParameterTextValue("@fors",
  42. reader.GetStringValue("fors"));
  43. args.Database.SetParameterTextValue("@title",
  44. reader.GetStringValue("title"));
  45. args.Database.SetParameterTextValue("@description",
  46. reader.GetStringValue("description"));
  47. args.Database.SetParameterTextValue("@area",
  48. reader.GetStringValue("area"));
  49. args.Database.ExecuteNonQuery();
  50. }
  51. }
  52. finally
  53. {
  54. reader.Close();
  55. }
  56. }
  57. return true;
  58. }
  59. catch (Exception exp)
  60. {
  61. args.WriteDebug(exp.Message);
  62. return false;
  63. }
  64. }
  65. }
  66. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.