// ServerDirectoryInfo DotNet System.IO.DirectoryInfo.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' // ServerFiles DotNet System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' // ServerFile DotNet System.IO.FileInfo.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' // iCount Integer // NoOfFiles Integer ServerDirectoryInfo := ServerDirectoryInfo.DirectoryInfo('c:\temp\test'); ServerFiles := ServerDirectoryInfo.GetFiles(); NoOfFiles := ServerFiles.Length(); FOR iCount := 0 TO NoOfFiles - 1 DO BEGIN ServerFile := ServerFiles.GetValue(iCount); MESSAGE('File No. %1\File Name %2',iCount + 1,ServerFile.Name); END;
TYPE := GETDOTNETTYPE(arr); MethodInfo := TYPE.GetMethods().GetValue(80); Parameters := Parameters.CreateInstance(GETDOTNETTYPE(Object),2); Parameters.SetValue(arrKey,0); Parameters.SetValue(arr,1); MethodInfo.Invoke(TYPE, Parameters);
Answers
Maybe may question was not written fully understandable? Sorry for my bad english, if somebody has experience with the topic above, but did not understand where my problem is: Don't hesitate to ask for clarification. On the other side, maybe it's kind of phantom problem? Thank you in advance.
Thomas
does that help?
https://stackoverflow.com/questions/34439416/list-of-files-from-a-directory-ordered-by-date
Your links shows a solution with LINQ. I am not sure if u can even use it in Dynamics NAV.
Cool, did not see that. I'll give it a try!
Thx for your help
Thomas
Just tried it on NAV2016.
Unfortunately i get this error:
"A call to System.Reflection.RuntimeMethodInfo.Invoke failed with this message: Parameter count mismatch."
Line: MethodInfo.Invoke(TYPE, Parameters);
Btw: My .NET experience is a bit limited, I don't fully understand that block anyway (especially the last line which is also the one throwing the error)
Any ideas?
Thanks
Thomas
i just copied the example, and it did work for me.
Anyway, you need to do it with .NET? What are you trying to reach - for what do you need the files sorted by date?
Thanks.
Strange, what NAV Version and what .NET Version did you use?
Can you copy your version of the code here, otherwise by PM?
They have to be ordered by date, because it's a kind of file interface. Oldest files must be processed first because some data will be re-delivered in newer files. Newest data is always the one we need.
I could change to something different but it's our design pattern here, proved in tons of cases and very flexible concerning server side vs. client side file system manipulations...
Btw: For the moment we have a workaround, file names are like "file_yyyymmdd.txt", so standard sorting on name does the trick too.
Thanks again
Thomas
NAV 2016 & .NET 4.0. I created a report and exported it to a ".txt" file.
https://pastebin.com/Us9KRqDL
That did work for me.
Thanks a lot. Strange, I've tested on different environments, even on a NAV 2018 (11.0.19846.0), with .NET Framework 4.5 installed. Everywhere the same error.
So u get the error as well with the report?
Well i am not sure, why u get this error. Have u tried the solution without .NET?
As mentioned above, I have a workaround, still using .NET, but sorting on the name. The name has the date part as a postfix. Sort is almost as good as on the change date itself.
I think I'll keep it like that, because it is not a super critical process.
Thanks again four your help.