Below is Code to delete attached document from forms in Axapta. If you want to delete all files from folder then this code sample can help you. Here word document considered as attachment for particular records.
COM wordApplication;
COM wordDocuments;
COM wordDoc;
DocuRef docuRef,docuRef2;
DocuAction docuAction, createdDocuAction;
str document,foldername,filename,fileinfo,newfilename;
System.String[] filePath;
int fileCount,currentFileCount,len;
foldername =@"C:\DocsN\Document_Management\";
filePath =System.IO.Directory::GetFiles(foldername); //get listing of all files within the folder
fileCount = filepath.get_Length(); //get how many files were found
for(currentFileCount = 0; currentFileCount < fileCount ; ++currentFileCount)
{
fileinfo = filepath.GetValue(currentFileCount);
len = strLen(fileinfo);
filename = subStr(fileinfo,47,len);
filename = fileinfo;
// Create instance of Word application
wordApplication = new COM("Word.Application");
// Get documents property
wordDocuments = wordApplication.Documents();
WinApi::Deletefile(filename);
}
Comments