/// <summary> /// Allow the user to change a String to a NText, although this may affect performance. /// </summary> /// <param name="outputID"></param> /// <param name="outputColumnID"></param> /// <param name="dataType"></param> /// <param name="length"></param> /// <param name="precision"></param> /// <param name="scale"></param> /// <param name="codePage"></param> public override void SetOutputColumnDataTypeProperties(int outputID, int outputColumnID, Microsoft.SqlServer.Dts.Runtime.Wrapper.DataType dataType, int length, int precision, int scale, int codePage) { var outputColl = this.ComponentMetaData.OutputCollection; IDTSOutput output = outputColl.GetObjectByID(outputID); var columnColl = output.OutputColumnCollection; IDTSOutputColumn column = columnColl.GetObjectByID(outputColumnID); var sourceColl = output.ExternalMetadataColumnCollection; IDTSExternalMetadataColumn columnSource = sourceColl.GetObjectByID(column.ExternalMetadataColumnID); if (((column.DataType == DataType.DT_WSTR) || (column.DataType == DataType.DT_NTEXT)) && ((dataType == DataType.DT_NTEXT) || (dataType == DataType.DT_WSTR))) { column.SetDataTypeProperties(dataType, length, precision, scale, codePage); } else { base.SetOutputColumnDataTypeProperties(outputID, outputColumnID, dataType, length, precision, scale, codePage); } }
/// <summary> /// Connects to SharePoint and gets any columns on the target /// </summary> /// <param name="output"></param> /// <param name="p"></param> private void CreateExternalMetaDataColumns( IDTSOutput output, string sharepointUrl, string listName, string viewName, Dictionary <string, string> existingColumnData) { // No need to load if the Url is bad. if ((sharepointUrl == null) || (sharepointUrl.Length == 0)) { return; } // Need a list to continue if ((listName == null) || (listName.Length == 0)) { return; } // If the list has changed, then we do not want any of the exisiting column data to // influence it (provides a way to actually reset the names if needed) if (output.Description != listName) { existingColumnData.Clear(); output.Description = listName; } try { List <SharePointUtility.DataObject.ColumnData> accessibleColumns = GetAccessibleSharePointColumns(sharepointUrl, listName, viewName); foreach (var column in accessibleColumns) { // Setup the primary column details from the List IDTSExternalMetadataColumn dtsColumnMeta = output.ExternalMetadataColumnCollection.New(); if (existingColumnData.ContainsKey(column.Name)) { dtsColumnMeta.Name = existingColumnData[column.Name]; } else { dtsColumnMeta.Name = column.FriendlyName; } dtsColumnMeta.Description = column.DisplayName; dtsColumnMeta.Length = 0; dtsColumnMeta.Precision = 0; dtsColumnMeta.Scale = 0; if ("Boolean|AllDayEvent|Attachments|CrossProjectLink|Recurrence".Contains(column.SharePointType)) { dtsColumnMeta.DataType = DataType.DT_BOOL; } else if (column.SharePointType == "DateTime") { dtsColumnMeta.DataType = DataType.DT_DBTIMESTAMP; } else if ("Number|Currency".Contains(column.SharePointType)) { // Max = 100,000,000,000.00000 dtsColumnMeta.DataType = DataType.DT_R8; } else if ("Counter|Integer".Contains(column.SharePointType)) { dtsColumnMeta.DataType = DataType.DT_I4; } else if ("Guid".Contains(column.SharePointType)) { dtsColumnMeta.DataType = DataType.DT_GUID; } else { if (column.MaxLength == -1) { dtsColumnMeta.DataType = DataType.DT_NTEXT; dtsColumnMeta.Length = 0; } else { dtsColumnMeta.DataType = DataType.DT_WSTR; dtsColumnMeta.Length = column.MaxLength; } } IDTSCustomProperty fieldNameMeta = dtsColumnMeta.CustomPropertyCollection.New(); fieldNameMeta.Name = "Id"; fieldNameMeta.Description = "SharePoint ID"; fieldNameMeta.Value = column.Name; // Create default output columns for all of the fields returned and link to the original columns IDTSOutputColumn dtsColumn = output.OutputColumnCollection.New(); dtsColumn.Name = dtsColumnMeta.Name; dtsColumn.Description = dtsColumnMeta.Description; dtsColumn.ExternalMetadataColumnID = dtsColumnMeta.ID; IDTSCustomProperty fieldName = dtsColumn.CustomPropertyCollection.New(); fieldName.Name = fieldNameMeta.Name; fieldName.Description = fieldNameMeta.Description; fieldName.Value = fieldNameMeta.Value; dtsColumn.SetDataTypeProperties( dtsColumnMeta.DataType, dtsColumnMeta.Length, dtsColumnMeta.Precision, dtsColumnMeta.Scale, 0); } } catch (ApplicationException) { // Exception happened, so clear the columns, which will invalidate this object. output.ExternalMetadataColumnCollection.RemoveAll(); } }