So I have this function that's downloads a file from a specific path and the path is in a complete different folder path than the wwwroot. The folder is in a shared network folder. Nothing is downloading when it returns but i get no errors and it does say the file exists. When i change the return from PhysicalFile to File its says the files does not exist.
public FileResult DownloadFileFromFolder()
{
IEnumerable results = DataLayer.GetData(111);
foreach (Objects things in results)
{
if (things.ID == num)
{
filepath = things.FilePath;
filepath = filepath+"/copy.xlsx";
break;
}
}
FileInfo myFile = new FileInfo(@filepath);
bool exists = myFile.Exists;
return PhysicalFile( myFile.FullName,"application/octet-stream",
"Returned_file.xlsx");
}
I try to use static folder but i dont think im doing it right
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseCors("Policy");
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider("//path/to/folder/"),
RequestPath = new PathString("/folder"),
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Login}/{id?}");
});
}