|
Yeah a big thank you from Sweden as well!
__________________________________________________________________________________________________________
Spelsidorna where [DER] and [BSW] meet!
|
|
|
|
|
Hi,
I have a Console app which has to read files which are modified before only 12 hours or less than 12 hours, but when I am using the following Linq its Fetching me the files which are modified a 2 months back.
Linq is:
dynamic tempFiles = null;
<pre>
tempFiles = (from f in feedDir.GetFiles(strPattern, SearchOption.TopDirectoryOnly) select f)
.Where(x => x.LastWriteTime >= DateTime.Now.AddHours(-12));
</pre>
Please help me what can I do to get only the Files list which are modified 12 hrs or after 12 hrs before, like files which are modified just before, 1 minutes before etc up only 12 hours before but not older than that.
Thanks in advance, any help would very helpful - thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
See FileSystemInfo.LastWriteTime Property (System.IO)[^]:
Quote: Note This method may return an inaccurate value, because it uses native functions whose values may not be continuously updated by the operating system.
The value of the LastWriteTime property is pre-cached if the current instance of the FileSystemInfo object was returned from any of the following DirectoryInfo methods:
GetDirectories
GetFiles
GetFileSystemInfos
EnumerateDirectories
EnumerateFiles
EnumerateFileSystemInfos
To get the latest value, call the Refresh[^] method.
So you might get an old time stamp especially when the file has just been updated.
|
|
|
|
|
That code looks like it should work - although I'd be inclined to use the UTC timestamps instead, to avoid timezone issues.
DateTime cutoff = DateTime.UtcNow.AddHours(-12);
IEnumerable<FileInfo> tempFiles = feedDir
.EnumerateFiles(strPattern, SearchOption.TopDirectoryOnly)
.Where(f => f.LastWriteTimeUtc >= cutoff);
Can you find an example of an old file being returned from this query, and check the "date modified" column in Windows Explorer? That column should return the same value as the LastWriteTime property.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes works perfect
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Hi,
I have a C# application which is sending automatic Emails with some essential information, the body of the Email has to be in tabular format.
Can anybody please help me how can I write an Email which would be in tabular format? A code snippet, a link or even a suggestion would be very helpful for me.
Thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
You've been around here long enough to know that you start with Google. I can't believe that you didn't find anything at all to give you a starting point for your own code. All you have to do is Google for "sending HTML email".
|
|
|
|
|
=========
|Foo|Bar|
|Foo|Bar|
=========
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Yes Implemented thank you very much buddies
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Dear experts
The task I need to solve
For a legacy C++ application -let's call it NativeW32App.exe - I need to use an third party SDK to control an USB device and this SDK is only available as a .net assembly.
The whole SDK consists of about 70 assemblies and one of them -let's call it ThridPartyNetSDK - represents the interface for me.
The approach I go is, I implement a proxy in .net which is COMVisible and can be easely consumed by the C++ application.
So far everything works fine as long as the whole bunch of SDK assemblies is available in the directory from where the NativeW32App.exe is startet. And this (all assemblies in the app's directory) I try to avoid because it is one of about 50 SDK (from different third parties) we need to support.
So my next step was/is
Separate the SDK assemblies and my COMVisible proxy in a separate directory and hook into assembly resolving...
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(SDK_AssemblyResolve);
... where I load the assemblies from the separate directrory in my SDK_AssemblyResolve.
The problem
It seems, that the SDK itself is loading some DLLs dynamicaly relative to the AppDomain.CurrentDomain.BaseDirectory which is
my NativeW32App.exe 's startup directory.
The dirty (?) solution
I'm faking AppDomain.CurrentDomain.BaseDirectory in my proxy assembly class ctor
AppDomain.CurrentDomain.SetData("APPBASE", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
Now finally this works, but I have my doubts
a.) According to the MSDN documentation setting system values (and I assume "APPBASE" is one) should have no effect. But it works fine so far
b.) I assume this can have side effects and is not appropriate for production
c.) It seems that there are better way, e.g. creating the AppDomain by myself. But I have no idea how to manage this for a COM assembly consumer.
Is AppDomain.CurrentDomain.SetData dirty or not reliable for production?
Does anybody has a hint to solve it in a better way, maybe with seperate AppDomain or what else?
Thank you very much in advance for your comments.
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Apparently, you could have accomplished the same thing by accessing AppDomainSetup.ApplicationBase.
And since it has both a setter and a getter ... You just took a different route.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
No, that does not work. AppDomainSetup is only relevant in case you create a new app domain.
Anyway, thank you for your comment and a .
modified 19-Jan-21 21:04pm.
|
|
|
|
|
|
Looks promising, thank you for this. I will dive into it and another
Bruno
[Edit]
Just checked the link. That is what I'm currently doing. But the problem remains, that some of these assemblies (resolved by ResolveEventHandler) do dynamically load by themselve assemblies with the assumption that these assemblies are located in AppDomain.CurrentDomain.BaseDirectory .

modified 19-Jan-21 21:04pm.
|
|
|
|
|
what should be present using modules and visual basic version?
|
|
|
|
|
That is not a good question for several reasons. First, your subject line - this is a C# forum so it's not necessary to put that in the title. What would be useful, instead, is a meaningful description of the problem. Second, your question is unclear. Try to explain in more detail what it is that you wish to know.
This space for rent
|
|
|
|
|
Looking at his profile, I suspect this is a spammer-in-waiting.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I rather think you're right.
This space for rent
|
|
|
|
|
Anyone understand this question ?
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Nope, and I've got a ton of VB/VB.NET experience.
|
|
|
|
|
Are you sure all this reply is for me ?
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Well, you did ask if anyone understood the question.
|
|
|
|
|
I understood.
I have mistaken your signature with your answer.
Note: first link don't work.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Well, it used to work. I guess Chris and Company removed the post...
|
|
|
|
|