What are the options to delete a file from NAV?

Reedberg
Member Posts: 68
Hello all,
I am wokring with NAV3.6 Attain, NAV5 is used as a client.
The task is very simple: I have to delete a file from a folder.
I used the following code to delete a file:
FileSystemObjL - 'Windows Script Host Object Model'.FileSystemObject
However when my client runs this code he gets the following error message:
The only solution I can think of is to delete a file using File table, but path in File table is limited to 98 characters, while the average path length in my client network is about 150 characters, so using File table is not an option.
So, is there a way to fix DeleteFile method?
If no, what are the other options to delete files under NAV?
Any suggestions will be very appreciated!
I am wokring with NAV3.6 Attain, NAV5 is used as a client.
The task is very simple: I have to delete a file from a folder.
I used the following code to delete a file:
FileSystemObjL - 'Windows Script Host Object Model'.FileSystemObject
IF ISCLEAR(FileSystemObjL) THEN CREATE(FileSystemObjL); IF FileSystemObjL.FileExists(AttachPathL + AttachNameL) THEN FileSystemObjL.DeleteFile(AttachPathL + AttachNameL);It works just fine under my computer. I am able to delete files located on a local computer and somewhere in the network.
However when my client runs this code he gets the following error message:
I do understand that -2147352567 is a general Exception that has occurred on the DeleteFile component. The best way to solve it is to attach Visual Studio, enable Exceptions and locate the error. However this is not an option because my client won't let me install Visual Studio and do debugging.This message is for C/AL programmers: An exception was raised in method DeleteFile. The OLE control or Automation server has returned error (HRESULT) -214735267. The component did not provide the exception description.
The only solution I can think of is to delete a file using File table, but path in File table is limited to 98 characters, while the average path length in my client network is about 150 characters, so using File table is not an option.
So, is there a way to fix DeleteFile method?
If no, what are the other options to delete files under NAV?
Any suggestions will be very appreciated!
0
Answers
-
You can also use native C/AL code to delete a file:
IF EXISTS(AttachPathL + AttachNameL) THEN IF ERASE(AttachPathL + AttachNameL) THEN;
But if you can't delete the file through FileSystem-automation, I guess you also won't be able to delete it through the native NAV functions.No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0 -
ReedBerg,
it' s simple, your code is correct using filesystemobject could access modify or change any file in network or local.
but you need to install COMDLG32.OCX (library for client application) in each client which using that code you made
some client which had visual studio installed not need to re-register it. but in end user client you must register it. no need
to download the library because it' s already in the system folder.. don' t forget to run regsvr32 'comdlg32.ocx' for 32 bit and
regsvr32 'syswow64 path\comdlg32.ocx' for 64 bit0 -
william_akihisa, COMDLG32.OCX is installed as a library on a client computer, so this is not the case.
Luc Van Dyck, at least native function does not have limitation to 98 characters. I will try your solution and report the results here, may be it will work out.
Thank you for your replies!0 -
Luc Van Dyck,
Thank you very much for your reply.
I used the native NAV functions EXISTS and ERASE. They didn't delete a file but at least they displayed a meaningful error message stating that a file cannot be deleted because it is used by another program.
I didn't told the whole story in my first message for this post. The task was to create a file using NAS, send it via E-mail using SMPT codeunit and then delete the file. I failed on the deletion step. It occurred that the cause of the error was NAV bug:When you use the SMTP Mail codeunit (400) to send email messages that have attachments in Microsoft Dynamics NAV 5.0 Service Pack 1 (SP1), the attached files are not released until the Microsoft Dynamics NAV client is closed. Before you close the Microsoft Dynamics NAV client, if you try to delete the attached file, you receive the error message…
The bug can be fixed by KB 2280492.
After I implemented this KB to the client environment everything became fine and NAS hopefully started to delete files after sending them via e-mails.
So, once again, thank your for your valuables replied, they helped me to solve my issue!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions