You are invited to Log in or Register a free Frihost Account!

[C#] XML file not updating


I'm trying to setup an XML file on a server that i use to check several information like:
- Program Name
- Program Version
- Program Size
- If program is enabled
- and several other things.

Now, in my program done in C#, i'm initializing a new HTTPWebRequest and requesting the contents of the xml file.
Everything went ok but when i updated the XML file on the server and tried to use the program to check for updates, it didn't catch the new changes, instead it grabbed an older version (cached) of the XML file.

How can i prevent the program from getting a cached version of the file and getting a fresh new one every time?

Thank You.

WebRequest.CachePolicy Property

The current cache policy and the presence of the requested resource in the cache determine whether a response can be retrieved from the cache. Using cached responses usually improves application performance, but there is a risk that the response in the cache does not match the response on the server.

Default cache policy can be specified in the Machine.config configuration file or by setting the DefaultCachePolicy property for requests that use the Hypertext Transfer Protocol (HTTP) or Secure Hypertext Transfer Protocol (HTTPS) URI scheme.


// The following method demonstrates overriding the
// caching policy for a request.
public static WebResponse GetResponseNoCache(Uri uri)
    // Set a default policy level for the "http:" and "https" schemes.
    HttpRequestCachePolicy policy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Default);
    HttpWebRequest.DefaultCachePolicy = policy;
    // Create the request.
    WebRequest request = WebRequest.Create(uri);
    // Define a cache policy for this request only.
    HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
    request.CachePolicy = noCachePolicy;
    WebResponse response = request.GetResponse();
    Console.WriteLine("IsFromCache? {0}", response.IsFromCache);           
    return response;


Is that what you're looking for?
yes that was what i was searching for, thank you very much.

although now i noticed that the link you specified gives a class that only applies to "Microsoft .NET Framework version 2.0" but i'm working with th .NET version 1.1 and i am afraid it doesn't exist in it, so is there any other way to not use the cache?

since all the searches i have done from that link only work in the 2.0 version and i haven't found any for 1.1.
i have found a fix for this.

it seems that whenever i send a request with parameters then i always get a new version, that is why i have made a simple php script that echos the XML contents whenever it has been called with the correct parameters like: ?action=show for example.
Cool, is there any particular reason you're not using version 2.0 though? It's a free download after all.
i just don't want the users to go through the troubles of downloading the Framework v2.0, i want it to work with their already existing Framework v1.1.

i had a lot of troubles getting some users set up and if i change anything, i'm afraid that they'll get lost Smile
Related topics
NotePad Replacements
Search function
Do you use XML ?
Microsoft vs. open-source in file sizes
[php] Php Editor
The best way to dynamically transform XML
what is a google sitemap?
problem with hash from Perl XML::Simple
rss 2.0 feeds
java xml validator
<? php with .xml............?>
Weird file problem :(
Creating XML files using PHP
How to prepare a true "GOOGLE XML" file - SITEMAP.
Reply to topic    Frihost Forum Index -> Scripting -> Others

© 2005-2011 Frihost, forums powered by phpBB.