DeleteFile() публичный Метод

public DeleteFile ( string file ) : void
file string
Результат void
Пример #1
0
 private static void SafeDeleteFile(IsolatedStorageFile store)
 {
     try
     {
         store.DeleteFile(FILENAME);
     }
     catch (Exception)
     {
     }
 }
Пример #2
0
 private static void SafeDeleteFile(IsolatedStorageFile store)
 {
     try
     {
         store.DeleteFile(Filename);
     }
     catch (Exception ex)
     {
     }
 }
Пример #3
0
 private void DeleteAllFilesInDirectory(IsolatedStorageFile store, string path)
 {
     if (!store.DirectoryExists(path))
     {
         return;
     }
     var files = store.GetFileNames(path + "/*");
     foreach (var file in files)
     {
         store.DeleteFile(path + "/" + file);
     }
 }
Пример #4
0
 private void InnerClear(IsolatedStorageFile iso, string path) {
     var fs = iso.GetFileNames(string.Format("{0}/*", path));
     foreach (var f in fs) {
         iso.DeleteFile(Path.Combine(path, f));
     }
     var ds = iso.GetDirectoryNames(string.Format("{0}/*", path));
     foreach (var d in ds) {
         var sp = Path.Combine(path, d);
         this.InnerClear(iso, sp);
         iso.DeleteDirectory(sp);
     }
 }
Пример #5
0
 public static void SafeDeleteFile(IsolatedStorageFile storage, string fileName)
 {
     try
     {
         if (storage.FileExists(fileName))
         {
             storage.DeleteFile(fileName);
         }
     }
     catch (Exception)
     {
     }
 }
Пример #6
0
        public static void RecursiveDeleteDirectory(string directory, IsolatedStorageFile store)
        {
            foreach (var fileName in store.GetFileNames(directory + "\\*"))
            {
                store.DeleteFile(directory + "\\" + fileName);
            }

            foreach (var directoryName in store.GetDirectoryNames(directory + "\\*"))
            {
                RecursiveDeleteDirectory(directory + "\\" + directoryName, store);
            }

            store.DeleteDirectory(directory);
        }
Пример #7
0
 public override void Clear()
 {
     base.Clear();
     using ( _storage = IsolatedStorageFile.GetUserStoreForApplication() ) {
         try {
             foreach ( string file in _storage.GetFileNames( CACHE_FOLDER + @"\*" ) ) {
                 _storage.DeleteFile( GetFilePath( file ) );
             }
         }
         catch ( Exception e ) {
             e.ToString();
         }
     }
 }
Пример #8
0
 public void DeleteDirectoryRecursive(IsolatedStorageFile isolatedStorageFile, String dirName)
 {
     String pattern = dirName + @"\*";
     String[] files = isolatedStorageFile.GetFileNames(pattern);
     foreach (String fName in files)
     {
         isolatedStorageFile.DeleteFile(Path.Combine(dirName, fName));
     }
     String[] dirs = isolatedStorageFile.GetDirectoryNames(pattern);
     foreach (String dName in dirs)
     {
         DeleteDirectoryRecursive(isolatedStorageFile, Path.Combine(dirName, dName));
     }
     isolatedStorageFile.DeleteDirectory(dirName);
 }
 public static void DeleteDirectoryRecursively(IsolatedStorageFile storageFile, string directoryName)
 {
     var pattern = directoryName + @"\*";
     var files = storageFile.GetFileNames(pattern);
     foreach (var fileName in files)
     {
         storageFile.DeleteFile(Path.Combine(directoryName, fileName));
     }
     var dirs = storageFile.GetDirectoryNames(pattern);
     foreach (var dirName in dirs)
     {
         DeleteDirectoryRecursively(storageFile, Path.Combine(directoryName, dirName));
     }
     storageFile.DeleteDirectory(directoryName);
 }
Пример #10
0
 internal static void ClearSlFiles(string rFileName)
 {
     System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
     if (rFileName == null || rFileName.TrimEnd() == "")
     {
         isf.Remove();
     }
     else
     {
         if (isf.FileExists(rFileName))
         {
             isf.DeleteFile(rFileName);
         }
     }
     isf.Dispose();
 }
Пример #11
0
		// use the caller stack to execute some write operations
		private void Write (IsolatedStorageFile isf)
		{
			isf.CreateDirectory ("testdir");

			string filename = Path.Combine ("testdir", "file");
			using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream (filename, FileMode.Create, isf)) {
			}
			isf.DeleteFile (filename);

			isf.DeleteDirectory ("testdir");
			try {
				isf.Remove ();
			}
			catch (IsolatedStorageException) {
				// fx 1.x doesn't like removing when things "could" still be in use
			}
		}
Пример #12
0
        public static void TryToDeleteAllFiles(IsolatedStorageFile storageFolder, string directory)
        {
            if (storageFolder.DirectoryExists(directory))
            {
                try
                {
                    string[] files = storageFolder.GetFileNames(directory);
                    foreach (string File in files)
                    {
                        storageFolder.DeleteFile(directory + files);

                    }
                }
                catch (Exception)
                {
                    //ignoring the exception
                }
             }
        }
        private static void TryToDeleteAllFiles(IsolatedStorageFile storageFolder, string directory)
        {
            if (storageFolder.DirectoryExists(directory))
            {
                try
                {
                    string[] files = storageFolder.GetFileNames(directory);

                    foreach (string file in files)
                    {
                        storageFolder.DeleteFile(directory + file);
                    }
                }
                catch (Exception)
                {
                    // could be in use
                }
            }
        }
Пример #14
0
        public static void DeleteDirectory(IsolatedStorageFile store, String root)
        {
            String dir = root;

            //  delete file in current dir
            foreach (String file in store.GetFileNames(dir + "/*"))
            {
                store.DeleteFile(dir + "/" + file);
            }

            //  delete sub-dir
            foreach (String subdir in store.GetDirectoryNames(dir + "/*"))
            {
                DeleteDirectory(store, dir + "/" + subdir + "/");
            }

            //  delete current dir
            store.DeleteDirectory(dir);
        }
Пример #15
0
        public static void SafeDeleteFile(IsolatedStorageFile store)
        {
            try
            {

                store.DeleteFile(filename);

                IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
                if (settings.Contains("errordata"))
                {
                    settings.Remove("erroedata");
                }

            }

            catch (Exception)
            {

            }
        }
        /// <summary>
        /// Configures the diagnostic log
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="enable"> </param>
        public static void Configure(string fileName, bool enable) {
            try {
                _IsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();

                _FileName = fileName;

#if DEBUG
                if (_IsolatedStorage.FileExists(_FileName)) {
                    _IsolatedStorage.DeleteFile(_FileName);
                }
#endif

                IsEnabled = enable;
                if (enable) {
                    WriteLogFileHeader();
                }
            } catch (Exception ex) {
                Debug.WriteLine(ex.ToString());
            }
        }
Пример #17
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            MenuItem clickedLink = (MenuItem)sender;

            if (clickedLink != null)
            {
                ToDoItem toDoForDelete = clickedLink.DataContext as ToDoItem;
                fileName = toDoForDelete.ItemName;
                //删除图片
                System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
                if (isf.FileExists(toDoForDelete.ItemName + ".jpg"))
                {
                    isf.DeleteFile(toDoForDelete.ItemName + ".jpg");
                }
                //删除磁贴
                deleteTile();
                //  删除数据
                App.ViewModel.DeleteToDoItem(toDoForDelete);
            }
            this.Focus();
        }
Пример #18
0
        // Writes the button options to the isolated storage.
        public void Write(string filename, string content)
        {
            System.IO.IsolatedStorage.IsolatedStorageFile isoStore =
                System.IO.IsolatedStorage.IsolatedStorageFile.
                GetUserStoreForDomain();
            try
            {
                // Checks if the file exists and, if it does, tries to delete it.
                if (isoStore.GetFileNames(filename).GetLength(0) != 0)
                {
                    isoStore.DeleteFile(filename);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine
                    ("Cannot delete file " + ex.ToString());
            }

            // Creates the options file and writes the button options to it.
            System.IO.StreamWriter writer = null;
            try
            {
                System.IO.IsolatedStorage.IsolatedStorageFileStream isos = new
                                                                           System.IO.IsolatedStorage.IsolatedStorageFileStream(filename,
                                                                                                                               System.IO.FileMode.CreateNew, isoStore);

                writer = new System.IO.StreamWriter(isos);
                writer.WriteLine(content);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine
                    ("Cannot write options " + ex.ToString());
            }
            finally
            {
                writer.Close();
            }
        }
Пример #19
0
        public static Image LoadImageFromCache(string imageFileName, IsolatedStorageFile isolatedStorage,
                                               Bitmap defaultBitmap)
        {
            try
            {
                using (var stream = new IsolatedStorageFileStream(imageFileName, FileMode.Open, isolatedStorage))
                {
                    return Image.FromStream(stream);
                }
            }
            catch (ArgumentException)
            {
                // The file is not a valid image, delete it
                isolatedStorage.DeleteFile(imageFileName);

                return defaultBitmap;
            }
            catch
            {
                // Other erros, ignore
                return defaultBitmap;
            }
        }
Пример #20
0
        void PhotoTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK && e.ChosenPhoto != null)
            {
                System.Windows.Media.Imaging.WriteableBitmap  bmp = Microsoft.Phone.PictureDecoder.DecodeJpeg(e.ChosenPhoto);
                System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
                if (isf.FileExists("abc.jpg"))
                {
                    isf.DeleteFile("abc.jpg");
                }
                System.IO.IsolatedStorage.IsolatedStorageFileStream PhotoStream = isf.CreateFile("abc.jpg");
                System.Windows.Media.Imaging.Extensions.SaveJpeg(bmp, PhotoStream, 432, 645, 0, 100);      //这里设置保存后图片的大小、品质
                PhotoStream.Close();                                                                       //写入完毕,关闭文件流

                PhotoStream = isf.OpenFile("abc.jpg", System.IO.FileMode.Open, System.IO.FileAccess.Read); //读取刚刚保存的图片的文件流
                System.Windows.Media.Imaging.BitmapImage bmp1 = new System.Windows.Media.Imaging.BitmapImage();
                bmp1.SetSource(PhotoStream);                                                               //把文件流转换为图片
                PhotoStream.Close();                                                                       //读取完毕,关闭文件流

                System.Windows.Media.ImageBrush ib = new System.Windows.Media.ImageBrush();
                ib.ImageSource      = bmp1;
                tip.Background      = ib;//把图片设置为控件的背景图
                imageTip.Visibility = System.Windows.Visibility.Collapsed;
                if (imagePicker.Content.ToString() == txtnote.Resources.StringLibrary.imagename)
                {
                    if (MessageBox.Show(txtnote.Resources.StringLibrary.imagename, txtnote.Resources.StringLibrary.guanlian, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                    {
                        NavigationService.Navigate(new Uri("/txtnote;component/Pick.xaml", UriKind.Relative));
                    }
                }
                else
                {
                    appBar3();
                }
            }
        }
Пример #21
0
 private void DeleteCrashes(IsolatedStorageFile store, string[] filenames)
 {
     foreach (String filename in filenames)
     {
         store.DeleteFile(Path.Combine(CrashDirectoryName, filename));
     }
 }
Пример #22
0
        private void SendCrashes(IsolatedStorageFile store, string[] filenames)
        {
            foreach (String filename in filenames)
            {
                try
                {
                    Stream fileStream = store.OpenFile(Path.Combine(CrashDirectoryName, filename), FileMode.Open);
                    string log = "";
                    using (StreamReader reader = new StreamReader(fileStream))
                    {
                        log = reader.ReadToEnd();
                    }
                    string body = "";
                    body += "raw=" + HttpUtility.UrlEncode(log);
                    body += "&sdk=" + SdkName;
                    body += "&sdk_version=" + SdkVersion;
                    fileStream.Close();

                    WebRequest request = WebRequestCreator.ClientHttp.Create(new Uri("https://rink.hockeyapp.net/api/2/apps/" + identifier + "/crashes"));
                    request.Method = "POST";
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.Headers[HttpRequestHeader.UserAgent] = "Hockey/WP7";

                    request.BeginGetRequestStream(requestResult =>
                    {
                        try
                        {
                            Stream stream = request.EndGetRequestStream(requestResult);
                            byte[] byteArray = Encoding.UTF8.GetBytes(body);
                            stream.Write(byteArray, 0, body.Length);
                            stream.Close();

                            request.BeginGetResponse(responseResult =>
                            {
                                Boolean deleteCrashes = true;
                                try
                                {
                                    request.EndGetResponse(responseResult);
                                }
                                catch (WebException e)
                                {
                                    if ((e.Status == WebExceptionStatus.ConnectFailure) ||
                                        (e.Status == WebExceptionStatus.ReceiveFailure) ||
                                        (e.Status == WebExceptionStatus.SendFailure) ||
                                        (e.Status == WebExceptionStatus.Timeout) ||
                                        (e.Status == WebExceptionStatus.UnknownError))
                                    {
                                        deleteCrashes = false;
                                    }
                                }
                                catch (Exception)
                                {
                                }
                                finally
                                {
                                    if (deleteCrashes)
                                    {
                                        DeleteCrashes(store, filenames);
                                    }
                                }
                            }, null);
                        }
                        catch (Exception)
                        {
                        }
                    }, null);
                }
                catch (Exception)
                {
                    store.DeleteFile(Path.Combine(CrashDirectoryName, filename));
                }
            }
        }
Пример #23
0
 private static void SafeDeleteExceptionFile(IsolatedStorageFile store)
 {
     store.DeleteFile(filename);
 }
Пример #24
0
        private static void DeleteFileHelper(IsolatedStorageFile isoStore, string path)
        {
            int retries = 3;

            while (retries-- > 0)
            {
                try
                {
                    if (isoStore.FileExists(path))
                    {
                        isoStore.DeleteFile(path);
                    }
                    else
                    {
                        return;
                    }
                }
                catch (IsolatedStorageException)
                {
                    // random iso-store failures..
                    //
                    Thread.Sleep(50);
                }
                return;
            }
        }
Пример #25
0
        private static void Upgrade(IsolatedStorageFile store)
        {
            var files = new List<string>(
                store.GetFileNames());

            if (!files.Contains("Database.kdbx"))
                return;

            var appSettings = IsolatedStorageSettings
                .ApplicationSettings;

            string url;
            if (!appSettings.TryGetValue("Url", out url))
                url = null;

            var info = new DatabaseInfo();

            using (var fs = store.OpenFile("Database.kdbx", FileMode.Open))
            {
                var source = string.IsNullOrEmpty(url)
                    ? "WinPass" : DatabaseUpdater.WEB_UPDATER;

                var details = new DatabaseDetails
                {
                    Url = url,
                    Source = source,
                    Type = SourceTypes.OneTime,
                    Name = "WinPass 1.x database",
                };

                info.SetDatabase(fs, details);
            }

            store.DeleteFile("Database.kdbx");
            store.DeleteFile("Protection.bin");
            store.DeleteFile("Decrypted.xml");
        }
Пример #26
0
 private void ClearPassword(IsolatedStorageFile store)
 {
     store.DeleteFile(ParsedXmlPath);
     store.DeleteFile(ProtectionPath);
     store.DeleteFile(MasterPasswordPath);
 }
Пример #27
0
        public override void Store( string url, BitmapSource bitmap )
        {
            Deployment.Current.Dispatcher.BeginInvoke( () => {
                string fileName = GetFilePath( GetFileName( url ) );
                using ( _storage = IsolatedStorageFile.GetUserStoreForApplication() ) {
                    if ( _storage.FileExists( fileName ) ) {
                        _storage.DeleteFile( fileName );
                    }

                    using ( IsolatedStorageFileStream fileStream = _storage.CreateFile( fileName ) ) {
                        WriteableBitmap writeableBitmap = new WriteableBitmap( bitmap );
                        writeableBitmap.SaveJpeg( fileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, IMAGE_QUALITY );
                    }
                }
            } );
        }
Пример #28
0
 /// <summary>
 /// Deletes the saved state files from isolated storage.
 /// </summary>
 private void DeleteState(IsolatedStorageFile storage)
 {
     // get all of the files in the directory and delete them
     string[] files = storage.GetFileNames("ScreenManager\\*");
     foreach (string file in files)
     {
         storage.DeleteFile(Path.Combine("ScreenManager", file));
     }
 }
Пример #29
0
        private void LoadRepos(IsolatedStorageFile iso)
        {
            if (!iso.FileExists(RepoFilename))
                return;

            try
            {
                using (var stream = iso.OpenFile(RepoFilename, FileMode.Open, FileAccess.Read))
                using (var br = new BinaryReader(stream))
                {
                    var fileVer = br.ReadInt32();
                    var numContexts = br.ReadInt32();
                    for (int i = 0; i < numContexts; i++)
                    {
                        var login = br.ReadString();
                        foreach (var context in Contexts)
                        {
                            if (context.User.Login.Equals(login))
                            {
                                var numMyRepos = br.ReadInt32();
                                context.Repositories.Clear();
                                for (int j = 0; j < numMyRepos; j++)
                                {
                                    var repo = new Repo();
                                    repo.Load(br, fileVer);
                                    context.Repositories.Add(repo);
                                }
                                break;
                            }
                        }
                    }

                    br.Close();
                }
            }
            catch (EndOfStreamException)
            {
                iso.DeleteFile(RepoFilename);
            }
        }
Пример #30
0
        private void DeleteDirectory(string path, IsolatedStorageFile iso)
        {
            if (!iso.DirectoryExists(path))
            return;

              var folders = iso.GetDirectoryNames(path + "/" + "*.*");

              foreach (var folder in folders)
              {
            string folderPath = path + "/" + folder;
            DeleteDirectory(folderPath, iso);
              }

              foreach (var file in iso.GetFileNames(path + "/" + "*.*"))
              {
            iso.DeleteFile(path + "/" + file);
              }

              if (path != "")
            iso.DeleteDirectory(path);
        }
        private void recoverAccountItems(IsolatedStorageFile isolatedStorage, Dictionary<string, List<AccountItem>> transactionItems, List<string> fileMessages, List<Guid> accountIds, List<Guid> categoryIds = null)
        {
            var sum = 0;
            foreach (var pair in transactionItems)
            {
                var file = pair.Key;
                int num2 = 0;
                try
                {
                    var allTasks = this.dataContext.TallyScheduleTable.Where(p => p.ProfileRecordType == ScheduleRecordType.ScheduledRecord)
                        .ToList();

                    var taskId = Guid.Empty;

                    TallySchedule taskInfo = allTasks.Count > 0 ? allTasks[0] : null;

                    foreach (var item in pair.Value)
                    {
                        if (accountIds.Count(p => p == item.AccountId) > 0 && categoryIds.Count(p => p == item.CategoryId) > 0)
                        {
                            if (taskInfo != null && taskInfo.Id != item.AutoTokenId)
                            {
                                taskInfo = allTasks.FirstOrDefault(p => p.Id == item
                                    .AutoTokenId);
                            }

                            ExpenseOrIncomeScheduleHanlder.RecoverItemProcessor(item, taskInfo);
                            sum++;
                        }
                        else
                        {
                            fileMessages.Add("Failed to add item: {0}, cause of account or category mismatched.".FormatWith(new object[] { item.Id }));
                        }
                    }
                }
                catch (System.Exception exception2)
                {
                    num2++;
                    string destinationFileName = pair.Key.Replace(".xml", ".err.xml");
                    fileMessages.Add("Failed to add items in file: {0}, cause of account or category mismatched. Have Renamed data file to {1}. details:\r\n{2}".FormatWith(new object[] { pair.Key, destinationFileName, exception2.Message }));
                    isolatedStorage.MoveFile(file, destinationFileName);
                }

                if (num2 > 0)
                {
                    this.SaveErrorsTo("recoveryDataError.log", new string[] { "Some items can't add to database.\r\n" + fileMessages.ToStringLine<string>("\r\n") });
                }
                else
                {
                    isolatedStorage.DeleteFile(file);
                }
            }

            this.dataContext.SubmitChanges();
        }
Пример #32
0
        private void LoadAuth(IsolatedStorageFile isoStore)
        {
            if (isoStore.FileExists(AuthFilename))
            {
                try
                {
                    using (var stream = isoStore.OpenFile(AuthFilename, FileMode.Open, FileAccess.Read))
                    using (var br = new BinaryReader(stream))
                    {
                        var fileVer = br.ReadInt32();
                        var unameLen = br.ReadInt32();
                        var unameEncrypted = br.ReadBytes(unameLen);
                        var pwordLen = br.ReadInt32();
                        var pwordEncrypted = br.ReadBytes(pwordLen);
                        var unamePlain = ProtectedData.Unprotect(unameEncrypted, null);
                        var pwordPlain = ProtectedData.Unprotect(pwordEncrypted, null);
                        _username = System.Text.Encoding.UTF8.GetString(unamePlain, 0, unamePlain.Length);
                        _password = System.Text.Encoding.UTF8.GetString(pwordPlain, 0, pwordPlain.Length);
                        IsAuthenticated = true;
                        InitAuth(_username, _password);

                        var numContexts = br.ReadInt32();
                        Contexts.Clear();
                        for (int i = 0; i < numContexts; i++)
                        {
                            var usr = new User();
                            usr.Load(br, fileVer);
                            Contexts.Add(new Context() { User = usr });
                        }
                        AuthenticatedUser = Contexts[0].User;

                        br.Close();
                    }
                }
                catch (EndOfStreamException)
                {
                    isoStore.DeleteFile(AuthFilename);
                }
            }
            else
            {
                IsAuthenticated = false;
            }
        }
Пример #33
0
 // Can't delete unless empty. Must recursively delete files and folders
 private static void DeleteDirectory(IsolatedStorageFile storage, string dir)
 {
     foreach (var file in storage.GetFileNames(Path.Combine(dir, "*")))
     {
         storage.DeleteFile(Path.Combine(dir, file));
     }
     foreach (var subDir in storage.GetDirectoryNames(Path.Combine(dir, "*")))
     {
         DeleteDirectory(storage, Path.Combine(dir, subDir));
     }
     storage.DeleteDirectory(dir);
 }
Пример #34
0
 /// <summary>
 /// Deletes the saved state files from isolated storage.
 /// </summary>
 private void DeleteState(IsolatedStorageFile storage)
 {
     // glob on all of the files in the directory and delete them
     string[] files = storage.GetFileNames(System.IO.Path.Combine(m_sStorageDirName, "*"));
     foreach (string file in files)
     {
         storage.DeleteFile(Path.Combine(m_sStorageDirName, file));
     }
                 }
Пример #35
0
 public void Delete()
 {
     Storage.DeleteFile(systemFilename);
 }