title: Non System.Web substitute for HttpPostedFileBase?
body: <p>I am trying to move some <code>C#</code> MVC legacy code into a shared DLL. All went well so far, but I was asked that that shared DLL need not reference <code>System.Web</code> in any way.</p>
  
  <p>The only type used in that DLL from System.Web is <code>HttpPostedFileBase</code>:</p>
  
  <pre><code>public string ChangeAttachment(int userId, HttpPostedFileBase file)
  {
      string attachmentsFolderPath = ConfigurationManager.AppSettings["AttachmentsDirectory"];
      if (!Directory.Exists(attachmentsFolderPath))
      {
          Directory.CreateDirectory(attachmentsFolderPath);
      }
  
      string fileTarget = Path.Combine(attachmentsFolderPath, userId.ToString() + Path.GetExtension(file.FileName));
  
      if (File.Exists(fileTarget))
      {
          File.Delete(fileTarget);
      }
  
      file.SaveAs(fileTarget);
  
      return fileTarget;
  }
  </code></pre>
  
  <p>As you can see, no HTTP or Web functionality is needed here, as only its <code>FileName</code> and <code>SaveAs()</code> members are used.</p>
  
  <p>Is there a substitute that I can easily convert <code>HttpPostedFileBase</code> to it at <strong>the caller</strong>, so that all I need to pass as a parameter is a non-web file?</p>
  
  <p>Note: <code>HttpPostedFileBase</code> inherits directly from <code>System.Object</code>, not from any file class.</p>