FileUtil
This class contains methods and functions related to files.
Description
Gets a file from application´s export directory.
Return Function
The specified file as a FileAttachment object.
Parameters
| Name | Description | Type |
| path | File name | String |
Example
'Sends file by email
Dim AttachmentsList as New List(Of FileAttachment)()
AttachmentsList.Add(sdk.FileUtil.getFile("filename.txt"))
sdk.email.send("from@phcsoftware.com", "to@phcsoftware.com", "Subject", "Body" , True, AttachmentsList)
Description
Replaces invalid characters from a string.
\\ / \ * : ? < > | , & # + - will be replaced by -
‘ ’ will be replaced by ´
Return Function
String without invalid characters
Parameters
| Name | Description | Type |
| value | Original string | String |
Example
Dim stringWithoutInvChar as string = SDK.FileUtil.GetSafeName("**Hello//\\") Description
Creates a CSV file into the application´s export directory
Return Function
CSV file as a FileAttachment object
Parameters
| Name | Description | Type |
| filename | Name of the file to be created | String |
| lines | CSV content as a List(Of String) | List(Of String) |
Example
'Sends a list of all inactive clients by email
Dim listOfClients as List(Of ClVO) = SDK.Query.getEntityData(of ClVO)(New FilterItem(CL.inactivo, Comparison.Equal, "1"))
Dim csvContent As List(Of String) = (From client In listOfClients Select client.nome + ";"+ client.email).ToList 'Creates CSV content
SDK.FileUtil.WriteLinesToCsv("InactiveClients.csv",csvContent)
Dim AttachmentsList as New List(Of FileAttachment)()
AttachmentsList.Add(sdk.FileUtil.getFile("InactiveClients.csv"))
SDK.email.send("from@phcsoftware.com", "to@phcsoftware.com", "Subject", "Body" , True, AttachmentsList)
Description
Extracts an attachment file from Anexos table
Return Function
PHCResult
Parameters
| Name | Description | Type |
| anexoStamp | Stamp of the attachment to be extracted (Anexos.anexosstamp) | String |
Example
This example shows how to send an attachment file by e-mail
Dim result As PHCResult = SDK.FileUtil.GenerateAttachmentFile("z202202151256037970038957")
If Not result.HasMsgErrors
Dim filename As String = result.result.Cast(Of StringVO).FirstOrDefault.phcString
Dim emailAttachments As New List(Of FileAttachment)
emailAttachments.Add(sdk.FileUtil.getFile(filename))
If sdk.email.send("from@phcsoftware.com", "to@phcsoftware.com", "Example of sending an attachment file", "This is an example of sending an attachment file by email", True, emailAttachments)
Return New MsgInfo("The attachment file has been sent by e-mail ")
End If
End If Description
Creates zip file from files
Return Function
n/a
Parameters
| Name | Description | Type |
| files | List of filenames to zip | String |
| zipFileName | Name of the zip file that will be created | String |
Example
This example shows how to send two attachment files by e-mail. The files will be sent using a ZIP file.
Dim files As New List(Of String)
Dim result As PHCResult = SDK.FileUtil.GenerateAttachmentFile("z202202151256037970038957")
If Not result.HasMsgErrors
files.Add(result.result.Cast(Of StringVO).FirstOrDefault.phcString)
End If
result = SDK.FileUtil.GenerateAttachmentFile("z202202151131063340048166")
If Not result.HasMsgErrors
files.Add(result.result.Cast(Of StringVO).FirstOrDefault.phcString)
End If
Dim zipFileName as string = "myFiles.zip"
sdk.FileUtil.createZipFromFiles(files, zipFileName)
Dim emailAttachments As New List(Of FileAttachment)
emailAttachments.Add(sdk.FileUtil.getFile(zipFileName))
If sdk.email.send("from@phcsoftware.com", "to@phcsoftware.com", "Example of sending an zip file", "This is an example of sending an zip file by email", True, emailAttachments)
Return New MsgInfo("The zip file has been sent by e-mail ")
End If
Description
Attachs file from application’s export directory in database
Return Function
PHCResult
Parameters
| Name | Description | Type |
| filename | Name of the file to be attached | String |
| resumo | Attachment summary | String |
| description | Additional remarks about the attachment | String |
| entity | NName of entity to which the attachment will be assigned | String |
| docid | Entity document type | Integer |
| recstamp | If it is a record attachment, it must contain the record stamp | String |
Example
'Attach a CSV file in Company Profile table (E1)
'First creates the CSV file
dim listOfInactiveClients as List(Of ClVO) = SDK.Query.getEntityData(of ClVO)(New FilterItem(CL.inactivo, Comparison.Equal, "1"))
Dim csvContent As List(Of String) = (From client In listOfInactiveClients Select client.nome + ";"+ client.email).ToList
sdk.FileUtil.WriteLinesToCsv("InactiveClients.csv",csvContent)
'Then attachs the CSV file
sdk.FileUtil.createBDAttachment("InactiveClients.csv","List of inactive clients"," List of inactive clients on date " + DateTime.Now().Date,"E1", 0, "")
Description
Creates a txt file into the application's export directory.
Return Function
Txt file as a FileAttachment object.
Parameters
| Name | Description | Type |
| filename | Name of the file to be created e | String |
| content | File content | String |
Example
'Sends a list of all inactive clients by email
Dim listOfClients as List(Of ClVO) = SDK.Query.getEntityData(of ClVO)(New FilterItem(CL.inactivo, Comparison.Equal, "1"))
Dim txtContent As String = ""
Dim spacer as Integer = 50
For each client as ClVO in listOfClients
txtContent = txtContent & client.nome & Space(spacer-client.nome.length) & client.email & vbCrLf
Next
sdk.FileUtil.createTxtFile("InactiveClients.txt",txtContent)
Dim AttachmentsList as New List(Of FileAttachment)()
AttachmentsList.Add(sdk.FileUtil.getFile("InactiveClients.txt"))
sdk.email.send("from@phcsoftware.com", "to@phcsoftware.com", "Subject", "Body" , True, AttachmentsList)