1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
public FileResult btnTelechargerFichier(string Emplacement)
{
byte[] fileBytes = System.IO.File.ReadAllBytes(Emplacement);
string fileName = ExtractFilename(@Emplacement);
return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
}
public static string ExtractFilename(string filepath)
{
if (filepath.Trim().EndsWith(@"\"))
return String.Empty;
int position = filepath.LastIndexOf('\\');
if (position == -1)
{
if (System.IO.File.Exists(Environment.CurrentDirectory + Path.DirectorySeparatorChar + filepath))
return filepath;
else
return String.Empty;
}
else
{
if (System.IO.File.Exists(filepath))
return filepath.Substring(position + 1);
else
return String.Empty;
}
} |
Partager