Here two examples for AX 2009 how to write files into DB and write files to
file system.
All code is written from scratch and not tested. Please avoid using table
docuValue, that's just an example!
void fromFolderToDB(FilePath _path)
{
System.IO.DirectoryInfo dir = new
System.IO.DirectoryInfo(_path);
System.IO.FileInfo[] files;
System.IO.FileInfo curFile;
System.Collections.IEnumerator enumerator;
BinData binData;
DocuValue docuValue;
;
files = dir.GetFiles(_path);
enumerator = files.GetEnumerator();
while (enumerator.MoveNext())
{
curFile = enumerator.get_Current();
docuValue.clear();
binData.loadFile(curFile.get_FullName()); // get file content
docuValue.File = binData.getData();
docuValue.FileName = curFile.get_Name();
docuValue.insert(); // insert into DB
}
}
void fromDBToFolder(FilePath _path)
{
BinData binData;
DocuValue docuValue;
;
while select docuValue // load From DB
{
binData.setData(docuValue.File);
binData.saveFile(docuValue.FileName); // insert into file system
}
}
Make attention to CodeAccessPermission when reading/writing to file system
and when using CLR inside X++.
Best regards
Patrick