c# - Get the field list of flat file connection? -
how write function (external function, c#, f# or powershell script, etc)
list<string> getfields(string ssispackagename, string filesourcename);
to field list of ssis package? since package xml file, can xquery used list?
or better, more information,
class field { public string name { get; set; } public string type { get; set; } } list<field> getfields(string ssispackagename, string filesourcename);
@billinkc right, should keep data typing issues in mind. said, @ best retrieve code page , unicode values flat file connection manager itself. following code should started, might need lookups code page , data type attributes.
string path = @"mypathto\package.dtsx"; xnamespace dts = "www.microsoft.com/sqlserver/dts"; xdocument doc = xdocument.load(path); // connections var connections = ele in doc.descendants(dts + "connectionmanager") ele.attributes(dts + "objectname").count() != 0 select ele; foreach (var connection in connections) { // flat file connection if (connection.attribute(dts + "objectname").value == "flat file connection manager") { var connectiondetails = connection.element(dts + "objectdata").element(dts + "connectionmanager"); console.writeline("codepage: " + connectiondetails.attribute(dts + "codepage").value); console.writeline("unicode: " + connectiondetails.attribute(dts + "unicode").value); var columnlist = connection.descendants(dts + "flatfilecolumn"); foreach (var column in columnlist) { console.writeline("column name: " + column.attribute(dts + "objectname").value); console.writeline("column type: " + column.attribute(dts + "datatype").value); } } }
Comments
Post a Comment