/ Published in: C#
The script will export data into existing tabels in SQL Server. The tables will use identity integer primary keys instead of the unique identifier keys Visual Web Ripper uses by default. New Tables Needed:
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//------------------------------------ CREATE TABLE [dbo].[VacationHome]( [VacationHomeId] [int] IDENTITY(1,1) NOT NULL, [Title] [nvarchar](1000) NOT NULL, [Description] [ntext] NOT NULL, CONSTRAINT [PK_VacationHomes] PRIMARY KEY CLUSTERED ( [VacationHomeId] ASC )) CREATE TABLE [dbo].[VacationHomeImage]( [VacationHomeImageId] [int] IDENTITY(1,1) NOT NULL, [VacationHomeId] [int] NOT NULL, [Photo] [image] NOT NULL, [PhotoFileName] [nvarchar](500) NOT NULL, CONSTRAINT [PK_VacationHomeImage] PRIMARY KEY CLUSTERED ( [VacationHomeImageId] ASC )) //---------------------------------- using System; using mshtml; using VisualWebRipper; public class Script { //See help for a definition of WrExportArguments. public static bool ExportData(WrExportArguments args) { try { args.Database.SetSqlAndPrepare("insert into VacationHome (Title, Description) values (@title,@description)"); WrSharedDatabase idCommand = args.Database.SetNewSqlAndPrepare("SELECT @@IDENTITY"); WrSharedDatabase imageCommand = args.Database.SetNewSqlAndPrepare ("insert into VacationHomeImage (VacationHomeId, Photo, PhotoFileName) values (@vacationHomeId,@photo, @photoFileName)"); WrExportTableReader vacationHomeReader = args.ExportData.GetTableReader( "VacationhomesSqlServer"); try { while (vacationHomeReader.Read()) { args.Database.SetParameterTextValue("@title", vacationHomeReader.GetStringValue("title")); args.Database.SetParameterTextValue("@description", vacationHomeReader.GetStringValue("description")); args.Database.ExecuteNonQuery(); int vacationHomeId = (int)((decimal) idCommand.ExecuteScalar()); WrExportTableReader vacationHomeImageReader = vacationHomeReader.GetChildTableReader( "photos"); try { while (vacationHomeImageReader.Read()) { imageCommand.SetParameterIntValue("@vacationHomeId", (int)vacationHomeId); imageCommand.SetParameterBinaryValue("@photo", (byte[]) vacationHomeImageReader.GetFieldValue("photo")); imageCommand.SetParameterTextValue("@photoFileName", vacationHomeImageReader.GetStringValue("photo File Name")); imageCommand.ExecuteNonQuery(); } } finally { vacationHomeImageReader.Close(); } } } finally { vacationHomeReader.Close(); } return true; } catch(Exception exp) { args.WriteDebug("Custom script error: " + exp.Message); return false; } } }