错误:找不到类型或命名空间名称“fileInfoNew”

时间:2011-07-25 02:46:14

标签: c# asp.net

以下代码给出了错误

  

错误:找不到类型或命名空间名称'fileInfoNew'(您是否缺少using指令或程序集引用?)

我尝试添加资源EntityFramework,但是出现了错误:

  

找不到引用的组件'EntityFramework'。

代码失败

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

namespace ST_18ff7a6acad54a089ed1d4a93700a713.csproj
{
    [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {

    enum ScriptResults 
    { 
        Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success, 
        Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure 
    }; 

        public void Main()
        {
            string[] sourceFiles = Directory.GetFiles(Dts.Variables["Y:\\Monoday\\Rachael\\PromasterFiles\\Partners YTD Promaster Monthly Transaction list.xlsx"].Value.ToString()); 
            DateTime highestDate = new DateTime();             
            int lastDate = 01/07/11 ;
            int fileInfo;
            int fileInfoNew;                                                                                                                                                    
            Boolean runPackage = false;

            foreach (string currentFile in sourceFiles)             
            {                                  
                fileInfo = new fileInfoNew(currentFile);                                                  

                if (fileInfo > lastDate)                 
                {                                        
                    lastDate = fileInfo; 
                    runPackage = true;                 
                }             

            }   

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

2 个答案:

答案 0 :(得分:1)

您应始终使用DateTime而不是整数。像这样:

    public void Main()
    {
        string[] sourceFiles = Directory.GetFiles(Dts.Variables["Y:\\Monoday\\Rachael\\PromasterFiles\\Partners YTD Promaster Monthly Transaction list.xlsx"].Value.ToString()); 
        DateTime lastDate = new DateTime(2011, 7, 1);
        Boolean runPackage = false;

        foreach (string currentFile in sourceFiles)             
        {                                  
            DateTime lastModifyDate = File.GetLastWriteTimeUtc(currentFile);                                                  

            if (lastModifyDate > lastDate)                 
            {                                        
                lastDate = lastModifyDate; 
                runPackage = true;                 
            }             

        }   


    }

答案 1 :(得分:0)

fileInfo = new fileInfoNew(currentFile)行没有意义。

fileInfofileInfoNew都是int个。特别是,fileInfoNew不是一种类型,即使你试图像它一样使用它。

您似乎正在尝试从文件列表中获取最新文件,但这应该使用DateTime来完成,而不是int s:

DateTime lastModifyDate = File.GetLastWriteTimeUtc(currentFile);