(Get "Temporary Internet Files" directory and files)            
const int cookies = 32;
Shell32.Folder objFolder;
Shell32.FolderItems objFolderItems;
Shell32.ShellClass objShell;

            string strFolderpath = System.IO.Path.GetTempPath().Substring(0, System.IO.Path.GetTempPath().Length - 1) + "orary Internet Files\\";
            objShell = new Shell32.ShellClass();
            objFolder = objShell.NameSpace(cookies);
            objFolderItems = objFolder.Items();


            foreach (Shell32.FolderItem objFolderItem in objFolderItems)
            {

                //MessageBox.Show(strFolderpath+objFolderItem.Path.ToString());

                string strDeleteFile = strFolderpath + objFolderItem.Path.ToString();

                File.Delete(strDeleteFile);//delete cannot

            }

Edited 3 Years Ago by happygeek: fixed formatting

CODE:(Get "Temporary Internet Files" directory and files)

        const int cookies = 32;
        Shell32.Folder objFolder;
        Shell32.FolderItems objFolderItems;
        Shell32.ShellClass objShell;

        string strFolderpath = System.IO.Path.GetTempPath().Substring(0, System.IO.Path.GetTempPath().Length - 1) + "orary Internet Files\\";
        objShell = new Shell32.ShellClass();
        objFolder = objShell.NameSpace(cookies);
        objFolderItems = objFolder.Items();


        foreach (Shell32.FolderItem objFolderItem in objFolderItems)
        {

            //MessageBox.Show(strFolderpath+objFolderItem.Path.ToString());

            string strDeleteFile = strFolderpath + objFolderItem.Path.ToString();

            File.Delete(strDeleteFile);//delete cannot

        }

Edited 3 Years Ago by __avd: fixed formatting.

private static void ClearCache(string fileName,string fileType)
        {

// fileName = * to delete all files with sp.ext
// fileType = * to delete with all ext

            String[] files = System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache),
               fileName + "."+ fileType + ", System.IO.SearchOption.AllDirectories);

            foreach (String filePath in files)
            {
                try
                {
                    System.IO.FileInfo f = new System.IO.FileInfo(filePath);
                    f.Delete();
                }
                catch (System.Security.SecurityException se)
                {
                    continue;
                }
                catch (UnauthorizedAccessException uae)
                {
                    continue;
                }
                catch (System.IO.IOException ie)
                {
                    continue;
                }
            }
        }

Edited 3 Years Ago by Dani: Formatting fixed

This article has been dead for over six months. Start a new discussion instead.