以下代码给出了错误
错误:找不到类型或命名空间名称'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;
}
}
}`
答案 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)
行没有意义。
fileInfo
和fileInfoNew
都是int
个。特别是,fileInfoNew
不是一种类型,即使你试图像它一样使用它。
您似乎正在尝试从文件列表中获取最新文件,但这应该使用DateTime
来完成,而不是int
s:
DateTime lastModifyDate = File.GetLastWriteTimeUtc(currentFile);