none
Files to pick by Other App RRS feed

  • Question

  • I have a documents (.pdf, .docx) that needs to be picked by other Application B based on fileName parameter. 

    The other Application B, does not need to parse or do anything. Just pick the files from this folder and send it to other Application A. But for some reason the files are not getting picked. Am I missing more logic 

    Please advise

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
    
    namespace FilePicker
    {
        class Program
        {
            static void Main(string[] args)
            {
                string directoryPath = @"<path to your files>";
                string[] filters = new string[] { "*.md", "*.docx", "*.pdf" };
                List<string> fileList = new List<string>();
    
                foreach (string filter in filters)
                {
                    var files = Directory.GetFiles(directoryPath, filter);
                    
                    foreach (string file in files)
                    {
                        fileList.Add(file);
                    }
                }
    
                foreach (string file in fileList)
                {
                    byte[] fileContents = File.ReadAllBytes(file);
                    
                }
            }
        }
    }
    


    RH

    Thursday, August 22, 2019 1:59 AM

All replies

  • Hi Dan2890,

    Thank you for posting here.

    According to your description, it seems that you could not filter the correct file from the path by using the above code, right?

    If so, I want to confirm if there are other folders containing files under the current path. You could try to use the following code to solve this problem.

         var files = Directory.GetFiles(directoryPath, filter, SearchOption.AllDirectories);

    If not, please describe it more clearly.

    Best Regards,

    Jack


    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.

    Thursday, August 22, 2019 2:51 AM
    Moderator
  • Greetings again Dan

    I'm not sure I understand the question, because I can't see how you are trying to pass files from one application to another, but I can say one thing.

    "<path to your files>" is not a valid path, so if that is your exact code, GetFiles will not find anything. If you are copying this code from a textbook, it probably means you to insert an actual path on your own computer in that place, like "c:\MyFolder", or whatever.
    Thursday, August 22, 2019 3:18 AM