title: How to restrict the file types in FileUpload in MVC3?
body: <p>I have a fileupload function where users can upload files. I want to restrict the users from upload certain file types. The types allowed are: <strong>.doc,.xlsx,.txt,.jpeg</strong>.</p>
  
  <p>How I can do this?</p>
  
  <p>This is my actual file upload code:</p>
  
  <pre><code>      public ActionResult UploadFile(string AttachmentName, BugModel model)
         {            
          BugModel bug = null;
          if (Session["CaptureData"] == null)
          {
              bug = model;
          }
          else
          {
              bug = (BugModel)Session["CaptureData"];
          }
          foreach (string inputTagName in Request.Files)
          {
              HttpPostedFileBase file1 = Request.Files[inputTagName];
              if (file1.ContentLength &gt; 0)
              {
                  string path = "/Content/UploadedFiles/" + Path.GetFileName(file1.FileName);
                  string savedFileName = Path.Combine(Server.MapPath("~" + path));
                  file1.SaveAs(savedFileName);
                  BugAttachment attachment = new BugAttachment();
                  attachment.FileName = "~" + path.ToString();
                  attachment.AttachmentName = AttachmentName;
                  attachment.AttachmentUrl = attachment.FileName;
                  bug.ListFile.Add(attachment);
                  model = bug;
                  Session["CaptureData"] = model;
              }
          }
          ModelState.Clear();
          return View("LoadBug", bug);
      }
  </code></pre>