0

I need to download a file from local folder using the partial file name,which is provided by the client side to the following function on Controller (RESTFUL API).

        [HttpGet]
        public IActionResult downloadTextFile(string partialName)
        {
            downloadTextFileFromLocal(partialName);
            return null;
        }

        private static void downloadTextFileFromLocal(string partialName)
        {
            //string partialFileName = "2018-10-3";
            DirectoryInfo hdDirectoryInWhichToSearch = new DirectoryInfo(@"D:\TextFile");
            FileInfo[] filesInDir = hdDirectoryInWhichToSearch.GetFiles("*" + partialName + "*.*");
            foreach (FileInfo foundFile in filesInDir)
            {
                string fullName = foundFile.FullName;
                Console.WriteLine(fullName);
            }
        }

Using this there isn't any error but the file doesn't downloads. How can i do this?

6
  • You do understand that ASP.NET code runs on the server, and that the server can't access your client's filesystem? Commented Jul 11, 2019 at 8:30
  • OK , So how can I give access to Local Folder ? or any other ways to do this? Commented Jul 11, 2019 at 8:43
  • What do you mean by "local folder" anyway? Also, your downloadTextFileFromLocal() method is a static void, it doesn't do anything. Do you intend to return a filename if something is found (on the server), and then return that file to the user? Commented Jul 11, 2019 at 9:05
  • 3
    @BirazDahal start with explaining what you actually want to do. Download from local is self-contradictory. Download **to** local means downloading a file from the server to a local folder on the user's machine. That's easy, explained in the docs and multiple SO questions - use return File(pathToTheServerFile). If you want to send a file to the server, you upload it Commented Jul 11, 2019 at 9:07
  • 3
    To upload a local file to the server, you use an input type='file' control in HTML, or execute a properly written POST request with the file's contents. Again, there are multiple SO questions that show how to do this Commented Jul 11, 2019 at 9:09

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.