Carlos Alves
Carlos Alves

Reputation: 48

How to save file in Temporary Internet Files

I want create cache some files .js after windows initialization with my console application, but i'm not able.

My code:

var tempFilePath = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
var filePath = Path.Combine(tempFilePath,"My.js");

var requestFile = (HttpWebRequest)HttpWebRequest.Create("http://my-address/My.js");
requestFile.Method = "GET";

var httpResponse = (HttpWebResponse)(requestFile.GetResponse());

using (var responseStream = httpResponse.GetResponseStream())
{
    var myJS = new StreamReader(responseStream).ReadToEnd();

    File.WriteAllText(filePath, myJS);
}

Upvotes: 1

Views: 878

Answers (1)

arizonawayfarer
arizonawayfarer

Reputation: 39

So, in order to write files directly to the IE cache folder, you'll need to use wininet.dll

You can use the CreateUrlCacheEntry and CommitUrlCacheEntryW functions to inject files into the cache.

Reference 1.

Reference 2.

Upvotes: 1

Related Questions