Exemple #1
0
        public IActionResult DownloadView(int id)
        {
            DownloadItem downloadItem = null;

            foreach (DownloadCategory category in _downloadProvider.DownloadCategoriesGet(UserId()))
            {
                foreach (DownloadItem item in category.Downloads)
                {
                    if (item.Id == id)
                    {
                        downloadItem = item;
                        break;
                    }
                }

                if (downloadItem != null)
                {
                    break;
                }
            }

            if (downloadItem == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            ViewDownloadViewItem model = new ViewDownloadViewItem(downloadItem.Id,
                                                                  downloadItem.Name, downloadItem.Description, downloadItem.Version,
                                                                  downloadItem.Filename, downloadItem.Icon, downloadItem.Size);

            return(View(model));
        }
Exemple #2
0
        public FileStreamResult DownloadFile(ViewDownloadViewItem model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            string path = model.Filename;
            string name = Path.GetFileName(path);
            string ext  = Path.GetExtension(path) ?? String.Empty;

            Response.Headers.Add("content-disposition", $"attachment; filename={name}");
            return(File(new FileStream(path, FileMode.Open), GetContentType(ext)));
        }