|
3 | 3 | using System.IO; |
4 | 4 | using System.Linq; |
5 | 5 | using System.Net.Mime; |
| 6 | +using System.Text; |
6 | 7 | using System.Web.Mvc; |
7 | 8 | using SmartStore.Admin.Extensions; |
8 | 9 | using SmartStore.Admin.Models.DataExchange; |
@@ -633,37 +634,56 @@ public ActionResult DownloadLogFile(int id) |
633 | 634 | return AccessDeniedView(); |
634 | 635 |
|
635 | 636 | var profile = _importService.GetImportProfileById(id); |
636 | | - if (profile == null) |
637 | | - return RedirectToAction("List"); |
638 | | - |
639 | | - var path = profile.GetImportLogPath(); |
640 | | - var stream = new FileStream(path, FileMode.Open); |
| 637 | + if (profile != null) |
| 638 | + { |
| 639 | + var path = profile.GetImportLogPath(); |
| 640 | + if (System.IO.File.Exists(path)) |
| 641 | + { |
| 642 | + var stream = new FileStream(path, FileMode.Open); |
| 643 | + var result = new FileStreamResult(stream, MediaTypeNames.Text.Plain); |
641 | 644 |
|
642 | | - var result = new FileStreamResult(stream, MediaTypeNames.Text.Plain); |
| 645 | + return result; |
| 646 | + } |
| 647 | + } |
643 | 648 |
|
644 | | - return result; |
| 649 | + return RedirectToAction("List"); |
645 | 650 | } |
646 | 651 |
|
647 | 652 | public ActionResult DownloadImportFile(int id, string name) |
648 | 653 | { |
649 | | - if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageImports)) |
650 | | - return AccessDeniedView(); |
| 654 | + string message = null; |
651 | 655 |
|
652 | | - var profile = _importService.GetImportProfileById(id); |
653 | | - if (profile == null) |
654 | | - return RedirectToAction("List"); |
| 656 | + if (_services.Permissions.Authorize(StandardPermissionProvider.ManageImports)) |
| 657 | + { |
| 658 | + var profile = _importService.GetImportProfileById(id); |
| 659 | + if (profile != null) |
| 660 | + { |
| 661 | + var path = Path.Combine(profile.GetImportFolder(true), name); |
655 | 662 |
|
656 | | - var path = Path.Combine(profile.GetImportFolder(true), name); |
| 663 | + if (!System.IO.File.Exists(path)) |
| 664 | + path = Path.Combine(profile.GetImportFolder(false), name); |
657 | 665 |
|
658 | | - if (!System.IO.File.Exists(path)) |
659 | | - path = Path.Combine(profile.GetImportFolder(false), name); |
| 666 | + if (System.IO.File.Exists(path)) |
| 667 | + { |
| 668 | + var stream = new FileStream(path, FileMode.Open); |
| 669 | + var result = new FileStreamResult(stream, MimeTypes.MapNameToMimeType(path)); |
| 670 | + result.FileDownloadName = Path.GetFileName(path); |
660 | 671 |
|
661 | | - var stream = new FileStream(path, FileMode.Open); |
| 672 | + return result; |
| 673 | + } |
| 674 | + } |
| 675 | + } |
| 676 | + else |
| 677 | + { |
| 678 | + message = T("Admin.AccessDenied.Description"); |
| 679 | + } |
662 | 680 |
|
663 | | - var result = new FileStreamResult(stream, MimeTypes.MapNameToMimeType(path)); |
664 | | - result.FileDownloadName = Path.GetFileName(path); |
| 681 | + if (message.IsEmpty()) |
| 682 | + { |
| 683 | + message = T("Admin.Common.ResourceNotFound"); |
| 684 | + } |
665 | 685 |
|
666 | | - return result; |
| 686 | + return File(Encoding.UTF8.GetBytes(message), MediaTypeNames.Text.Plain, "DownloadImportFile.txt"); |
667 | 687 | } |
668 | 688 |
|
669 | 689 | [HttpPost] |
|
0 commit comments