none
What is the best way to get a list of urls in my favorites folder and save it to a collection data structure? RRS feed

  • Question

  • I need some help with creating a list of urls in my favorites folder. I need to know if I need to open each file, which is of type .url and parse it to match the url and save it to a list<string> or is a there a better way to do it? That is, can I save the other information in the .url file? if I can, I like to do it. Are there types in C#, which I should use besides the string type? If there are types that make other tasks easier I like to know about it please.

    Here is what I have so far: 

    string favorites = @"C:\Users\usr\Favorites";
                if (File.Exists(favorites))
                {
                    // This path is a file
                    ProcessFile(favorites);
                }
                else if (Directory.Exists(favorites))
                {
                    // This path is a directory
                    ProcessDirectory(favorites);
                }
                else
                {
                    Console.WriteLine("{0} is not a valid file or directory.", favorites);
                }
            }
            // Process all files in the directory passed in, recurse on any directories 
            // that are found, and process the files they contain.
            public static void ProcessDirectory(string targetDirectory)
            {
                // Process the list of files found in the directory.
                string[] fileEntries = Directory.GetFiles(targetDirectory);
                foreach (string fileName in fileEntries)
                    ProcessFile(fileName);
    
                // Recurse into subdirectories of this directory.
                string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
                foreach (string subdirectory in subdirectoryEntries)
                    ProcessDirectory(subdirectory);
            }
            // Insert logic for processing found files here.
            public static void ProcessFile(string path)
            {
                Console.WriteLine("Processed file '{0}'.", path);
                // Add the file to the list of internet shortcut files 
            }
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                textBox1.Text = string.Empty;
            }

    Wednesday, October 10, 2018 2:30 AM

All replies

  • Hi Zolfaghar,

    Thank you for posting here.

    Try to use Uri.

    List<Uri> uri = new List<Uri>();

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Friday, October 12, 2018 7:02 AM
    Thursday, October 11, 2018 7:28 AM
    Moderator
  • You can find example code here, just modify it so it appends to your List<string> instead of treeview.
    Thursday, October 11, 2018 7:54 AM
    Answerer
  • Thank you both. 
    Thursday, October 11, 2018 8:05 PM
  • Hi Zolfaghar,

    If the reply is helpful, please mark it as answer, it will be beneficial to other communities who have similar issue.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 16, 2018 7:55 AM
    Moderator