在BizTalk中,可以通过自定义C#代码来获取输入文件名。以下是一个示例解决方案:
using Microsoft.BizTalk.Component.Interop;
using Microsoft.BizTalk.Message.Interop;
using System.Data.SqlClient;
namespace BizTalkProject
{
public class CustomPipelineComponent : IComponent
{
public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
{
// 获取输入文件名
string fileName = (string)pInMsg.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties");
// 使用文件名进行SQL查询
string connectionString = "Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=True";
string query = "SELECT * FROM TableName WHERE FileName = @FileName";
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Parameters.AddWithValue("@FileName", fileName);
connection.Open();
// 执行查询操作
SqlDataReader reader = command.ExecuteReader();
// 处理查询结果
while (reader.Read())
{
// 处理查询结果
}
reader.Close();
}
}
return pInMsg;
}
// 实现其他IComponent接口的成员
// ...
}
}
通过这个解决方案,当BizTalk接收到文件时,它将使用自定义管道对文件进行处理,并在处理过程中获取输入文件名,并使用该文件名进行SQL查询。