title: Downloading Multiple Files; ASP.NET MVC C#
body: <p>I am having issues with downloading files in ASP.NET MVC using Visual Studio. The main purpose of my code is to store licensing files in my local file system. My upload function is working fine, however, my download function is not. Because the database I am using is unable to store lists, I currently store each file name in a string as such: "9-0.lic,9-1.lic,9-2.lic,". The first number (9) is the primary key for my SoftwareLicense Model, and the number after the dash is the license file number (1, 2 and 3).</p>
  
  <p>SoftwareLicense Model:</p>
  
  <pre><code>public class SoftwareLicense
  {
      [Key]
      public int SoftwareID { get; set; } // Properties of class SoftwareLicense
  
      public int UserID { get; set; }
      [ForeignKey("UserID")]
      public virtual IntranetUser User { get; set; }
  
      [Required(ErrorMessage = "Software title field is required.")]
      [Display(Name = "Software Title")]
      public string SoftwareName { get; set; }
  
      [Required(ErrorMessage = "The software key field is required")]
      [Display(Name = "Software Key")]
      public string SoftwareKey { get; set; }
  
      [Required(ErrorMessage = "The software price field is required")]
      [Display(Name = "Software Price")]
      public decimal Price { get; set; }
  
      [Display(Name = "License File")]
      public string LicenseFileName { get; set; }
  
      [Display(Name = "File Path")]
      public string LicenseFilePath { get; set; }
  
      [Required(ErrorMessage = "The start date field is required.")]
      [Display(Name = "Start Date")]
      public DateTime StartDate { get; set; }
  
      [Required(ErrorMessage = "The end date field is required")]
      [Display(Name = "End Date")]
      public DateTime EndDate { get; set; }
  
      [Required(ErrorMessage = "The license type field is required")]
      [Display(Name = "License Type")]
      public string LicenseType { get; set; }
  
      [Display(Name="Department Name")]
      public string DepartmentName { get; set; }
  
      [Required(ErrorMessage = "The notify time field is required")]
      [Display(Name = "Notify Time")]
      public int NotifyTime { get; set; }
  
      [Required(ErrorMessage = "The email field is required")]
      [Display(Name = "Entry Created By")]
      public string Email { get; set; }
  
      public bool Active { get; set; }
  }
  </code></pre>
  
  <p>PreDownload Method in SoftwareLicense Controller:</p>
  
  <pre><code>public ActionResult PreDownload(int ID)
      {
          SoftwareLicense softwareLicense = db.SoftwareLicenses.Find(ID);
  
          var fileNames = softwareLicense.LicenseFileName.Split(',');
  
          foreach(string fileName in fileNames)
          {
              if(fileName.Length &gt; 1)
              {
                  Download(fileName, softwareLicense.SoftwareName);
              }
          }
          SetUserInfo();
          return View("Details", softwareLicense);
      }
  </code></pre>
  
  <p>Download Method in SoftwareLicense Controller:</p>
  
  <pre><code>public FileResult Download(string fileName, string licenseName)
      {
          string returnName = licenseName + '-' + fileName;
  
          if((fileName != "") || (fileName != " "))
          {
              return File("C:/Users/heathera/Desktop/Licenses/" + fileName, MediaTypeNames.Application.Octet, returnName);
          }
          else
          {
              return null;
          }
  
      }
  </code></pre>
  
  <p>If anyone has any pointers or solutions please let me know, I have been stuck on this for a day or two now and can't seem to figure it out. Also, if you have any pointers on any of my code I am always willing to learn about smarter programming.</p>
  
  <p>Thanks in advance!
  Andrew.</p>