Call a custom .NET component to move large file from one file location to another

Home Page Forums BizTalk 2004 – BizTalk 2010 Call a custom .NET component to move large file from one file location to another

Viewing 1 reply thread
  • Author
    Posts
    • #22422

      Hi guys,

      Need some help to write a custom .NET component to move a large file from one file location to another. I have tried using  the following code. But I am not really sure how to call these C# class from BizTalk Orchestration. Hope I can get some help here. Any suggestions on how to improve the file movement code will be useful too.

      Thanks.

      -Optimus

       

              // Display Directory info
              DirectoryInfo dir1 = new DirectoryInfo(@”C:\TestMove\Outgoing”);
             
              // Display Files in directory
              FileInfo[] files = dir1.GetFiles(“*.*”);
              Console.WriteLine(“Total number of files: {0}”, files.Length);
              foreach (FileInfo f in files)
              {
                  String path = “c:\\TestMove\\Outgoing\\” + f.Name;
                  String path2 = “D:\\TestMove\\Incoming\\” + f.Name;

                  try
                  {
                      if (!File.Exists(path))
                      {
                          // This statement ensures that the file is created,
                          // but the handle is not kept.
                          using (FileStream fs = File.Create(path)) { }
                      }

                      // Ensure that the target does not exist.
                      if (File.Exists(path2))
                      {
                          Console.WriteLine(“{0}, File exists at target. Do you want to overwrite?”, f.Name);
                          Console.WriteLine(“Please enter y to overwrite or n to exit”);
                          String answer = Console.ReadLine();
                          if (answer == “y”)
                          {
                              File.Delete(path2);
                          }
                          else if (answer == “n”)
                          {
                              Console.Write(“File is not overwritten. Program will exit.”);
                          }
                          else
                          {
                              Console.Write(“Error, nothing is entered. File is not overwritten. Program will exit.”);
                          }
                      }

                      // Move the file.
                      File.Move(path, path2);
                      Console.WriteLine(“{0} was moved to {1}.”, path, path2);

                      // See if the original exists now.
                      if (File.Exists(path))
                      {
                          Console.WriteLine(“The original file still exists, which is unexpected.”);
                      }
                      else
                      {
                          Console.WriteLine(“The original file no longer exists, which is expected.”);
                      }

                  }
                  catch (Exception e)
                  {
                      Console.WriteLine(“\n\nThe process failed: {0}”, e.ToString());
                  }
              }

    • #22449

      If your goal is only to move a file from one location to another, you can setup a FILE send port with filter to subscribe any message/file that’s coming from a specific send port, location that meets certain criterias.

      Otherwise, you could write all your code in a helper .net class and call your function to write move the file to the new location. Hope this helps.

Viewing 1 reply thread
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.