Exemple #1
0
        //delete all tags from selected files

        private void deleteTags(object sender, RoutedEventArgs e)
        {
            string docFilePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Tags.xml";

            XDocument xmlDocument = XDocument.Load(docFilePath);

            XDocument doc;

            doc = XDocument.Load(docFilePath);



            if (lb_tag.Items.Count > 0)
            {
                string           messageBoxText = "Are you sure you want to delete tags from those files" + "?";
                MessageBoxButton button         = MessageBoxButton.YesNo;
                MessageBoxImage  icon           = MessageBoxImage.Warning;
                if (MessageBox.Show(messageBoxText, null, button, icon) == MessageBoxResult.No)
                {
                    return;
                }

                List <string> fileslist = lb_tag.Items.Cast <String>().ToList();

                string streamName = ":fileTags";



                FileStream stream = NtfsAlternateStream.Open(fileslist[0] + streamName, FileAccess.ReadWrite, FileMode.OpenOrCreate, FileShare.None);
                stream.Close();
                IEnumerable <NtfsAlternateStream> fileStream = NtfsAlternateStream.EnumerateStreams(fileslist[0]);

                for (var i = 0; i < fileslist.Count; i++)
                {
                    NtfsAlternateStream.Delete(fileslist[i] + streamName);


                    doc.Element("root").Elements("tag").Elements("path")

                    .Where(x => x.Attribute("value").Value == fileslist[i]).Remove();


                    doc.Save(docFilePath);
                }


                MessageBox.Show("Tags deleted successfuly");
            }
            else
            {
                MessageBox.Show(" you have to drag the files you want to tag ");
            }

            lb_tag.Items.Clear();
            doc = XDocument.Load(docFilePath);
            return;
        }
Exemple #2
0
        public void DeleteFileTags() //delete all ads from file
        {
            string streamName = ":fileTags";

            if (checkTagFileExists(this._path))
            {
                FileStream stream = NtfsAlternateStream.Open(this._path + streamName, FileAccess.ReadWrite, FileMode.OpenOrCreate, FileShare.None);
                stream.Close();
                IEnumerable <NtfsAlternateStream> fileStream = NtfsAlternateStream.EnumerateStreams(this._path);
                foreach (NtfsAlternateStream ads in fileStream)
                {
                    if (ads.StreamType.ToString().Equals("AlternateData"))
                    {
                        if (ads.Name.Equals(streamName + ":$DATA"))

                        {
                            NtfsAlternateStream.Delete(this._path + streamName);
                        }
                    }
                }
            }
        }
Exemple #3
0
        private void listBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Open();
            }
            else if (e.KeyCode == Keys.Delete)
            {
                if (listBox1.SelectedItem == null)
                {
                    return;
                }

                var stream = listBox1.SelectedItem as NtfsAlternateStream;
                if (stream == null)
                {
                    return;
                }

                try
                {
                    DialogResult dialogResult = MessageBox.Show(string.Format("Are you sure you want to delete '{0}'", stream.Name), "Confirm", MessageBoxButtons.YesNoCancel);
                    if (dialogResult != DialogResult.OK && dialogResult != DialogResult.Yes)
                    {
                        return;
                    }

                    NtfsAlternateStream.Delete(_path + stream.Name);
                    listBox1.Items.Remove(listBox1.SelectedItem);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex);
                }
            }
        }