none
How to rename filename in Orchestration using .net code ? RRS feed

  • Question

  • Hi - I have a requirement where once the files are written in the folder, then only I have to rename the file.

    In Orchestration using .net code, how can I rename the file name ?


    MBH

    Thursday, October 13, 2016 7:07 PM

All replies

  • Hi,

    Use the following expression in a expression shape. :

    Orchmsg(FILE.ReceivedFileName) = ABCName

    There is a similar thread here, please check this .

    https://social.msdn.microsoft.com/Forums/en-US/8cb8beac-a887-4bc3-95f4-3daa699d0745/rename-file-in-orchestration?forum=biztalkgeneral


    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.



    Thursday, October 13, 2016 7:21 PM
  • Hi,

    Use  System.IO.File.Move, believe this has to be incorporated in a another .helper class and you can call that from your orchestration expression shape  at the end of all the send port transactions.

    System.IO.File.Move("oldfilename", "newfilename");


    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.


    Thursday, October 13, 2016 8:02 PM
  • Hi,

    I don't think so you will have to create a class file and method within to rename then create an object out of it to be used in your orchestration expression shape .


    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.

    Thursday, October 13, 2016 8:12 PM
  • Hi,

    The basic method should look like this

    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace YourRenaminApplication
    {
        class RenameProgram
        {
            private void RenameFile(string OldFilename)
            {
                System.IO.File.Move("OldFilename", "newFilename");
            }
        }
    }

           

    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.


    Thursday, October 13, 2016 8:39 PM
  • Hold on, you will have to include the required dll references in the class project then only it will compile.

    From your orchestration this is how you will call:

    1>Reference the Helper class project in your orchestration project

    2>Create a variable and set the type to the helper class (See below)

    4>Drag an expression shape to call this method.




    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.


    Thursday, October 13, 2016 8:54 PM
  • Hi,

    Is this helper class added to your orchestration project reference? if yes I dont see why it should not show the method. Try cleaning up the solution, removing re adding the helper class reference. Restart VS as well.

    One more point set the class public and then recompile

    public class ReplaceFileName


    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.


    Thursday, October 13, 2016 9:10 PM
  • Is the class set to public

    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.

    Thursday, October 13, 2016 9:32 PM
  • Hi,

    Well if the  helper class is referenced in orchestration project I do not see any reason for this to happen, let me try to mimic this and get back. In the interim I think you should try testing renaming file method for desired outcome, I would suggest you create a console application and test your.net  helper class to make sure it works.

    Best of luck.


    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.

    Friday, October 14, 2016 12:18 AM
  • Hi

    You have to elaborate your questions

    1) From the same orchestration are u sending the mutilple files with append mode or it is different orchestrations writing to the same file?

    while  sending the files to fileshare location,Where are setting the Address URI  for send port?

    Is it Dynamic send port or Static send port?

    If it is static send port--How do u know the send port address in orchestration?

    In case of dynamic send port--U will set the address in the orchestration and how do u know that the file is last file?

    Are u maintaining any flag variable or count logic?

    You need to share above details to get correct answer for your question?

    Friday, October 14, 2016 1:04 AM
  • Hi while you are close to a solution with the .net helper class you are working on.

    On a second thought have you considered using scheduling adapter 

    http://social.technet.microsoft.com/wiki/contents/articles/25101.biztalk-server-scheduling-orchestration-using-trigger-message.aspx

    Another idea would be after your orchestration is done processing all files, drop a zero byte / blank file and write another batch program which will move the bulk file if it finds the zero byte file to a new folder acting as an endpoint for your 2nd receive locatio. Have this batch file set in your windows scheduler and let it run on the day you expect the file to be ready every one hour.  You shall be good with either of the approach.

    But if I were you I would have gone with helper class, that's the most elegant approach .


    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.


    Friday, October 14, 2016 2:06 AM
  • The parameter file.move is going to take is absolute path of the file , the code I pasted was a skeleton structure (not tested) and like I said you May have to tweak it a bit and then test, and that's a pure .net portion of it.BizTalk orchestration inclusion is easy afterwards .

    thats why I was telling you to get the helper class ready first . I will try to mimic this as well if I get time . Best of luck again



    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.

    Friday, October 14, 2016 2:22 AM
  • Hi, make sure to sign and GAC the helper class Assembly and retry. But again your helper class in not truly ready. Thats why I would have tested that helper class stand alone first to make sure it is doing the file renaming (You are better off renaming and  moving file to a different location rather than just renaming). 

    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.


    Friday, October 14, 2016 2:32 AM
  • There could be the problem, you have added the helper class to an already GAC'd assembly.

    Try referencing your new project assembly directly into GAC ufter removing the old one from GAC (Please check the curent biztalk dll sitting in the GAC has your new helper calss or not), it shall work


    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.

    Friday, October 14, 2016 2:47 AM
  • Glad it worked :) happy Friday, You are going to need the absolute path

            

    string filename = @"c:\temp2\MyTest.txt";

    check this article on syntax

    https://msdn.microsoft.com/en-us/library/system.io.file.move%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396


    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.

    Friday, October 14, 2016 1:59 PM
  • Hi Ja,

    File.move  is going to work for renaming as well, I would suggest you try it .

    your method will take 2 parameters as following

    using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace YourRenaminApplication { [Serializable]

    public class RenameProgram { public void RenameFile(string OldFilename, string NewFilename) { System.IO.File.Move("OldFilename", "newFilename"); } } }

    In the orchestration create two string variables and assign the value as following.

    VarOldFile= @"c:\temp\OldName.xml";

    VarNewFileName= @"c:\temp\NewName.xml";

    pass these two in your method from orchestration expression as below

    VarRenameHelper.RenameFile(VarOldFile, VarNewFileName)

    Note: You may need to tweak it here and there since it is not a tested code.


    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.



    Friday, October 14, 2016 3:08 PM
  • Hi Ja,

    Let me create this solution and get back to you with working code when I get time. 


    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.

    Friday, October 14, 2016 5:08 PM
  • Let me create this solution and get back to you with working code when I get time. 

    Hi Pushpendra K Singh, thanks for the continued support, before you put in the effort, I want to tell you that I doubt this will help in any way.

    Hi jaguarjags, at this point, I recommend you put aside these various attempts and open a new thread restating your basic business scenario.  Following this path takes you further from a viable solution*.  Perhaps some new perspectives will help.

    *If this is related to the HL7 threads.

    Friday, October 14, 2016 6:37 PM
    Moderator
  • Hi Jaguarjags,

    A humble request to you  present your entire end to end scenario as johns suggested so that our experts can help you out.

    Regards,


    Mandar Dharmadhikari

    Friday, October 14, 2016 6:50 PM
    Moderator
  • Let me create this solution and get back to you with working code when I get time. 

    Hi Pushpendra K Singh, thanks for the continued support, before you put in the effort, I want to tell you that I doubt this will help in any way.

    Hi jaguarjags, at this point, I recommend you put aside these various attempts and open a new thread restating your basic business scenario.  Following this path takes you further from a viable solution*.  Perhaps some new perspectives will help.

    *If this is related to the HL7 threads.

    Hi Johns,

    I am not aware of HL7 background you mentioned about- Assuming core question in this forum was >> a file is published by an orchestration send port >> The same file needs to be renamed post the processing of the orchestration send  port so that another RL location can pick it .

    Trying to understand why this solution will not work? And what would be the approach one should rather take. Please let me know when you get time.


    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.

    Friday, October 14, 2016 11:16 PM
  • Hi Jag,

    Johns is one of the most knowledgable mentor or guide you can find in BizTalk community.So I differ here, if he says so there must be a rational and most of the times it is worth contemplating over.


    Regards Pushpendra Singh : Please mark the reply as answer or vote it up, as deemed fit.

    Friday, October 14, 2016 11:34 PM
  • Hi jaguarjags,

    It would be help for Pushpendra K Singh if you linked back to some of the original threads so he can understand your scenario at a higher level.

    Renaming files in an Orchestration is a highly, highly unusual procedure.  If he can see the full context of this question, I'm sure he can provide you with a better alternative.

    Saturday, October 15, 2016 12:13 PM
    Moderator
  • Hi jaguarjags,

    What I mean is, it would be helpful if he know why you were trying to do this in the overall business process.

    If this is related to the HL7 database load, explaining that requirement or referencing those original threads will help him give you the best advice on how to achieve that, likely without having to rebatch or modify files in an Orchestration.

    Monday, October 17, 2016 11:29 AM
    Moderator