Exemple #1
0
		public void Start(SP.ISPDatabase sharepointDatabase, SP.SPListDefinition list, UI.IProgressNotifier notifier)
		{
			notifier.Reset("Initializing...");
			_Formatter.Initialize();

			SP.SPFieldDefinitionCollection oFieldList = list.Fields;

			notifier.SetProgress("Retrieving records from Sharepoint database...", 0);

			System.Data.IDataReader oReader = sharepointDatabase.GetListItemsAsReader(list, true, false);

			oReader.Read();
			int nTotalRecords = oReader.GetInt32(0);
			int nProcessedRecords = 0;

			notifier.SetProgress(string.Format("{0} records retrieved.  Now exporting...", nTotalRecords.ToString()), 10);

			oReader.NextResult();
			while (oReader.Read())
			{
				int nListItemID = Convert.ToInt32(oReader["ID"]);

				_Formatter.BeginExportRow(nListItemID.ToString());

				foreach (SP.SPFieldDefinition oField in oFieldList)
				{
					_Formatter.ExportField(oField.InternalName, sharepointDatabase.GetFieldText(oField, oReader));
				}

				if (_Formatter.SupportAttachments && oReader.GetBoolean(oReader.GetOrdinal("HasAttachments")))
				{
					DataTable oAttachmentList = sharepointDatabase.GetListItemAttachmentsList(list, nListItemID, true);
					int nCounter = 1;

					foreach (DataRow oAttachment in oAttachmentList.Rows)
					{
						_Formatter.ExportAttachment(nCounter, oAttachment["Folder"].ToString(), oAttachment["Filename"].ToString(), (byte[]) oAttachment["Content"]);
						nCounter++;
					}
				}

				_Formatter.EndExportRow();
				nProcessedRecords++;

				if (nProcessedRecords % 100 == 0)
					notifier.SetProgress(null, (short) (10 + (nProcessedRecords * 90 / nTotalRecords)));
			}

			_Formatter.Terminate();
			notifier.SetComplete(null);
		}