spMFUpdateExplorerFileToMFiles¶
- Returns
1 = Success
-1 = Error
- Parameters
- @FileName nvarchar(256)
Name of the file
- @FileLocation nvarchar(256)
UNC or fully-qualified local path to the file folder
- @MFTableName nvarchar(100)
Class table name (e.g., ‘MFCustomer’)
- @SQLID int
The ID of the record (ID column) in the class table
- @IsFileDelete bit (optional)
Default = 0
Set to 1 to delete the source file after import
- @RetainDeletions bit (optional)
Default = 0 (No)
Set to 1 if the class table should retain deletions
- @IsDocumentCollection bit (optional)
Default = 0 (No)
Set to 1 if the class refers to a document collection
- @ProcessBatch_id int (output)
ProcessBatch ID for logging
- @Debug int (optional)
Default = 0
1 = Standard Debug Mode
101 = Advanced Debug Mode
Purpose¶
Attach a file from a folder to an object represented in a class table.
Additional Info¶
This functionality will:
Add the file to an object. If the object exists as a multi-document object with no files attached, the file will be added and the object converted to a single-file object. If files already exist, the new file is added to the collection.
The object must pre-exist in the class table. The class table metadata will be applied to object when adding the file. This procedure will add a new object from the class table, or update an existing object in M-Files using the class table metadata.
The source file will optionally be deleted from the source folder.
The procedure will not automatically change a multi-file document to a single-file document. To set an object to single-file, set the ‘Single_File’ column to 1 after adding the file.
Warnings¶
The procedure uses the ID in the class table (not ObjID) to reference the object. This allows referencing a record that does not yet exist in M-Files.
Examples¶
DECLARE @ProcessBatch_id INT;
DECLARE @FileLocation NVARCHAR(256) = 'C:\Share\Fileimport\2\'
DECLARE @FileName NVARCHAR(100) = 'CV - Tommy Hart.docx'
DECLARE @TableName NVARCHAR(256) = 'MFOtherDocument'
DECLARE @SQLID INT = 1
EXEC [dbo].[spMFUpdateExplorerFileToMFiles]
@FileName = @FileName
,@FileLocation = @FileLocation
,@SQLID = @SQLID
,@MFTableName = @TableName
,@ProcessBatch_id = @ProcessBatch_id OUTPUT
,@Debug = 0
,@IsFileDelete = 0
SELECT * FROM dbo.MFFileImport AS mfi;
Changelog¶
Date |
Author |
Description |
2023-05-19 |
LC |
Resolve issue with updating changed file |
2023-03-28 |
LC |
Allow option to set object to set object to single file |
2023-03-27 |
LC |
Improve logic for validation |
2023-01-23 |
lc |
Fix bug setting single file to 1 when count > 1 |
2022-12-07 |
LC |
Improve logging messages |
2022-09-02 |
LC |
Update to include RetainDeletions and DocumentCollections |
2021-08-03 |
LC |
Fix truncate string bug |
2021-05-21 |
LC |
improve handling of files on network drive |
2020-12-31 |
LC |
Improve error handling in procedure |
2020-12-31 |
LC |
Update datetime handling in mffileexport |
2019-08-30 |
JC |
Added documentation |