Skip to Content
Author's profile photo Jimmy Michael

Way to get unique filename if specified filename already exists (.NET) for exported production order from SAP Business One

About Production Order:

Production order can be exported as csv or txt files by using SAP Business One SDK. It can be also integrated to other system automatically.

When we exported the documents from SAP Business One, it will create a file that must have a name. The file name can be unique depends on the customer or end user requirement.

One of file name that can be used is based on the exported date and sequence. For example, the file name is PRDO20180101_1.txt. this file may contains more than one production orders or one production order only.  After that, the new production orders should be exported again. This activity repeats every day.

The new exported file will overwrite the existing file if the old file still exists.  I want it so that if the file exists it will increment new file names instead of overwriting the file. To achieve this, there are so many ways.  You can search in google but naming the file based on system date is new and unique.

I use to increment the system date based file name of exported production order files in SAP Business One SDK.

The file name Structure is : PRDO+SystemDate+Sequence No.

Here is the code:

Dim folderPath = Path.GetDirectoryName("C:\Users\Administrator\Desktop\")
Dim fileName = Path.GetFileNameWithoutExtension(("PRDO" + Date.Now.Year.ToString + Date.Now.Month.ToString("#00") + Date.Now.Day.ToString("#00") + "_"))
            Dim fileExt = Path.GetExtension("*.txt")
            Dim i = 0
            Dim filePath As String

                i += 1
                filePath = Path.Combine(folderPath, String.Format("{0}_{1}{2}", fileName, i, fileExt))
            Loop While File.Exists(filePath)



The file name in the code is based on the current date or system date. So, it will be renewed every day.

SAP Business One version I use is SAP B1 9.3 PL6 on MSSQL. Good luck.




Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.