full path as the filename

795 Views Asked by At

Maybe someone knows a simple solution to my problem. I do not know the entry of the file so it's not a static value. It can be changed through the BizTalk gui and there we have a URI through the receiveport. But I do not believe it's accessible that easy. What I want to do is write out the full path as the filename. It works well with the messageID where the file is given a specific filepath name. But the Path-Name where the file was dropped is not working that well. I keep getting this error :

Message: Object reference not set to an instance of an object.

the message resource is present but the message is not found in the string/message table -Does not say me much

Below you can see a snip from my code

internal static string UpdateMacroPathProperty(IBaseMessage baseMessage, string macroPathProperty, string macroDefsFile)
{
   if (macroName == "MessageID")
   {
      contextPropertyValue = baseMessage.MessageID.ToString();
   }
   else if (macroName == "SourceFileName")
   {               
      contextPropertyValue = Directory.GetCurrentDirectory();
   }
}

This is an specific created pipeline. Has anyone encountered this problem or can point me in the right way.

I know that BizTalk has a built in function for this, BizTalk Server: List of Macros as the %SourceFileName% but I'm trying to save this as logs in a specific map structure so that it does not get processed.

1

There are 1 best solutions below

0
Dan Field On

It's adapter dependent; some adapters will use the FILE adapter's namespace even though they're not the file adapter, but this is the kind of logic that I've used in the past for this:

string adapterType = (string)pInMsg.Context.Read("InboundTransportType",
    "http://schemas.microsoft.com/BizTalk/2003/system-properties");
string filePath = null;

if (adapterType != null)
{
    if (adapterType == "FILE")
    {
        filePath = (string)pInMsg.Context.Read("ReceivedFileName",
            "http://schemas.microsoft.com/BizTalk/2003/file-properties");
    }
    else if (adapterType.Contians("SFTP") && !adapterType.Contains("nsoftware")) 
    // nsoftware uses the FTP schema
    {
        filePath = (string)pInMsg.Context.Read("ReceivedFileName",
            "http://schemas.microsoft.com/BizTalk/2012/Adapter/sftp-properties");
    }
    else if (adapterType.Contains("FTP"))
    {
        filePath = (string)pInMsg.Context.Read("ReceivedFileName",
            "http://schemas.microsoft.com/BizTalk/2003/ftp-properties");
    }
}

And then you can just fall back to the MessageID if you can't get the file path from any of these.