2011-06-15 75 views
1

使用SSIS包,我生成ExcelSheet作爲輸出。我通過C#源代碼調用SSIS包。目前我實際上將文件保存爲:pkgTR.Variables [「dPath」]。Value = @「c:\」+ sFileName;動態保存SSIS包的輸出

我們希望功能另存爲最終用戶 - 誰決定將文件保存在C:\或D:\或他想要保存文件的位置。

try 
{ 
    string pkgTRPath = @"C:\Reports\SSISPackages\GenerateTransactionReport.dtsx"; 
    Package pkgTR; 
    Microsoft.SqlServer.Dts.Runtime.Application app; 
    DTSExecResult pkgResults; 

    app = new Microsoft.SqlServer.Dts.Runtime.Application(); 
    pkgTR = app.LoadPackage(pkgTRPath, null); 

    pkgTR.Variables["sConn"].Value = System.Configuration.ConfigurationManager.AppSettings["SSISConn"]; 
    pkgTR.Variables["sDate"].Value = txtFromDate.Text; 
    pkgTR.Variables["eDate"].Value = txtToDate.Text; 
    pkgTR.Variables["sSortCode"].Value = drpSortCode.SelectedValue.TrimEnd(); 
    string sFileName = "TransactionReport_" + drpSortCode.SelectedValue.TrimEnd() + ".xls"; 
    pkgTR.Variables["dPath"].Value = @"c:\" + sFileName; 

    pkgResults = pkgTR.Execute(); 
    var reportID = drpSortCode.SelectedValue.TrimEnd(); 

    if (pkgTR.ExecutionResult.ToString() == "Success") 
    { 
     Response.Write(String.Format(@"<script language=javascript>alert('Excel Report for {0} is Generated');</script>", reportID)); 
    } 
    else if (pkgTR.ExecutionResult.ToString() == "Failure") 
    { 
     Response.Write("<script language=javascript>alert('Failure:Unable to generate report!!');</script>"); 
    } 
} 

catch (Exception ex) 
{ 
    Console.WriteLine(ex.Message); 
} 

回答

1

如果要調用從C#你不能彈出在C#中的對話框包啓動包,然後通過目錄路徑到您的SSIS包當你執行之前?

+0

聽起來不錯,但.. ..任何示例代碼? – goofyui 2011-06-20 16:03:29