Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I did a code to delete my cookie file from the Temporary Internet files but its not working and going out of the foreach loop. The code is
C#
var path = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
foreach (FileInfo fileInfo in directoryInfo.GetFiles("Cookie:abc.xyz@dev.livestuff.com/.txt"))
{
   fileInfo.Delete();
}

Now what I have to do to delete my cookie file ?
Posted
Comments
DamithSL 13-Jun-14 9:00am    
how you create the cookie? update the question with that code
Priyanka Bhawsar 13-Jun-14 9:17am    
The cookies are created by the above domain and I want to delete it with my IE addon which is created for it .
DamithSL 13-Jun-14 9:10am    
what is your project type? web application or winform with web browser control etc.. please explain.
Priyanka Bhawsar 13-Jun-14 9:35am    
My project type is winform and I am using web browser control to call the above URL with iframe.

You can't.

There are all sorts of reasons, starting with:
1) Cookies are stored on the client, not the server, so you can't access them with C# code anyway except via the Cookies class.
2) They aren't stored in the same place by all browsers anyway: Chrome for example uses an SQLite database instead of individual files, and holds the DB open and locked while it is running, so you can't even access it directly without closing the browser.

Use the "normal" interface to remove cookies:
C#
if (Request.Cookies["UserId"] != null)
{
    Response.Cookies["UserId"].Expires = DateTime.Now.AddDays(-1);
}
Will direct the browser to remove it. What the browser actually does as a result though, it not defined...
 
Share this answer
 
Comments
Priyanka Bhawsar 13-Jun-14 9:25am    
I tried this but its not updating my cookie.
 
Share this answer
 
Comments
Priyanka Bhawsar 13-Jun-14 9:13am    
I have seen all the urls as you sent, but it will delete all the files. I want to delete only my file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900