读取具有"FileInfo"的对象变量.C#脚本任务中的对象内容 [英] Read an object variable having "FileInfo" object content in C# script task

查看:63
本文介绍了读取具有"FileInfo"的对象变量.C#脚本任务中的对象内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试循环并从共享点位置读取对象变量(如图所示),其中该文件包含文件详细信息(名称/大小/日期已修改).

I'm trying to loop and read an object variable(as shown in the pic) where it has the file details(name/size/datemodified) from a share point location.

基本上,我需要类似于以下代码的内容才能读取名称"值.

Basically I need something similar to below code to just read the "Name" value.

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
using System.Collections;
using System.Collections.Generic;

public void Main()
        {

            var fileinfo = Dts.Variables["User::DvarObj"].Value;
            Dts.Variables["User::Local"].Value = new List<String>();
            List<String> OutputFileNames = (List<String>)Dts.Variables["User::Local"].Value;
            var collection = fileinfo as IEnumerable;


            if (collection != null)
            {

                foreach (var item in collection)
                {

                    OutputFileNames.Add(item.GetType());
                }
            }


            var id = fileinfo.GetType().Name;

            Dts.TaskResult = (int)ScriptResults.Success;
        }

我不确定如何将名称"字段值添加到列表中.任何帮助深表感谢.

I'm not sure how to get the "Name" field value added to the list. Any help is much appreciated.

推荐答案

因此,这是一种类型,其中我们的对象包含对象值.因此,请使用以下方法来访问它.

So this is a type where we have objects containing objects values. So to access this please use the below method.

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
using System.Collections;
using System.Xml;
using System.Collections.Generic;
using System.Linq;
    public void Main()
        {

            var fileinfo = Dts.Variables["User::DvarObj"].Value;
            Dts.Variables["User::Local"].Value = new List<String>();
            List<String> OutputFileNames = (List<String>)Dts.Variables["User::Local"].Value;
            string outputresultnames = "";
            foreach (object element in (fileinfo as IEnumerable ?? Enumerable.Empty<object>()))
            {
                var type = element.GetType();
                var props = type.GetProperties();
                object result = props.First().GetValue(element, null);
                outputresultnames = (string)result;
                OutputFileNames.Add(outputresultnames);
            }

            Dts.Variables["User::Local"].Value = OutputFileNames;

            Dts.TaskResult = (int)ScriptResults.Success;
        }

这篇关于读取具有"FileInfo"的对象变量.C#脚本任务中的对象内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆