我想從用戶獲取文件名,然後根據該名稱我會得到另一個輸入。這是一個多輸入多輸出問題。 所以我規範化的問題如下。無法讀取平面文件源
1.我在控制流中使用Script Tast並要求輸入文件名在C#中使用表單。我正在瀏覽文件時獲取文件名。
2.然後解壓縮文件,並根據我設置的3個變量的全球文件的名稱檢查文件的名稱。
3.根據變量,我花了3個數據流任務。對於上述特定的問題,它的工作很好。
4.Its適用於不同的數據流任務。
但我有另一個問題,當我使用動態平面文件源名稱(使用表達式)它給我錯誤無法打開文件。
Error "[Flat File Source [1]] Error: Cannot open the datafile "C:\Documents and Settings\XQN4P\Desktop\Inputs\Intraday\OPTION_DAILY_INTRADAY_ASIA20140212.csv". "
請注意,此文件是由用戶將輸入文件解壓縮生成的。
有警告以及「[平面文件源[1]警告:因爲它正在使用由另一個進程的進程無法訪問該文件 」。
這裏是我用來解壓縮的代碼。
}
private void unzipInFile(string inputFilePath, string destDirectory,string destFileName)
{
FileStream fsIn =new FileStream (inputFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
FileStream fsOut =new FileStream(destDirectory +"\\"+destFileName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
int buffersize = 4096;
int count = 0;
var buffer= new byte [buffersize];
//using (Stream compressed = File.OpenRead(inputFilePath))
//using (ZlibStream zlib = new ZlibStream(compressed, CompressionMode.Decompress))
using(GZipStream gZip = new GZipStream(fsIn, Ionic.Zlib.CompressionMode.Decompress, Ionic.Zlib.CompressionLevel.BestCompression, true))
{
byte[] buf = new byte[short.MaxValue];
int bufl;
while (0 != (bufl = gZip.Read(buf, 0, buf.Length)))
{
if (count != 0)
fsOut.Write(buffer, 0, count);
if (count != buffersize)
return ;
}
}
fsOut.Close();
}
另一個地址變量
Dts.Variables["FileAddress"].Value = filePath + ".csv";
SSIS結構: 「ScriptTask」 將輸出發送到3級數據流的任務。
你可以發佈一些代碼在這裏 – vikky
嗨, 我認爲這個問題是在解壓縮文件,因爲我檢查的文件是空的它的確定。當我滑動unziping並把提取的文件放在那裏時,它正在工作。但我對解壓函數感到驚訝,爲什麼它不能在另一個函數中工作呢? –