Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need to get the latest file from a directory, so using LINQ I got the file name and gave that file path as a link. When I click the link the file opens. But the problem happens when I click the link for the second time, after closing it. The old content is getting displayed, even though the file has been updated.

I get the file using the following piece of code:

var directory = new DirectoryInfo("C:\\MyDirectory");
var myFile = (from f in directory.GetFiles()
             orderby f.LastWriteTime descending
             select f).First();`

Then i assign the above file with link to a label using the following code.

label.text="<a href=\"" + "Log\\" + myFile + "\" target = '_NEW' runat='server'>Click</a>"

share|improve this question
2  
How are you retrieving and viewing the file - do you have some sample code please? Are you sure it isn't being cached anywhere? –  dash Jun 11 '13 at 11:44
    
we cannot read your mind, mentioned code plz. –  Rahul Jun 11 '13 at 11:47
    
What do you then do with the file? –  dash Jun 11 '13 at 12:29
    
Its like a log file. –  VSMK Jun 11 '13 at 12:30
    
Do you write it out to the browser, for example? –  dash Jun 11 '13 at 12:31

2 Answers 2

up vote 3 down vote accepted

It's most likely related to a caching "issue".

The easiest workaround is to change your url, append a time (ticks) related name-value like "&t=654102310650".
That way the url will never be the same so the content will never get retrieved from the browser's cache.

share|improve this answer
1  
You could of course use the modification date of your file as time reference. –  Serge Jun 11 '13 at 12:43
    
I don't think i can use the query string because, i assign it to a label as shown in the above updated code. –  VSMK Jun 13 '13 at 7:34

FileSystemInfo.Refresh takes a snapshot of the file from the current file system. ....

Calls must be made to Refresh before attempting to get the attribute information, or the information will be outdated.

from here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.