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?
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?Download from localis self-contradictory.Download **to** localmeans 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 - usereturn File(pathToTheServerFile). If you want to send a file to the server, you upload itinput 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