title: How to view the doc file which is stored in the root folder in razor pages
body: <p>I need to view the uploaded doc file contents when clicking on the 'VIEW' button,
  My current code is downloading the file, instead of viewing the contents.
  Here is my code</p>
  <p>Attachment.cshtml</p>
  <pre><code>@if (Model.AttachForms != null)
              {
                  &lt;table class=&quot;table&quot; border=&quot;1&quot; style=&quot;width:500px;margin-left:300px;&quot;&gt;
                      &lt;thead style=&quot;background-color:#DC3545&quot;&gt;
                          &lt;tr&gt;
                              &lt;th&gt;File&lt;/th&gt;
                              &lt;th width=&quot;100px&quot;&gt;&lt;/th&gt;
                              &lt;th width=&quot;100px&quot;&gt;&lt;/th&gt;
                          &lt;/tr&gt;
                      &lt;/thead&gt;
                      &lt;tbody&gt;
                          @foreach (var item in Model.AttachForms)
                          {
                              &lt;tr&gt;
                                  &lt;td&gt;
                                      @Html.DisplayFor(modelItem =&gt; item.Name)
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      @*asp page handler with define on post method*@
                                      &lt;form asp-page-handler=&quot;view&quot; method=&quot;post&quot;&gt;
                                          &lt;input asp-for=&quot;EmpID&quot; type=&quot;hidden&quot; value='@Request.Query[&quot;EmpID&quot;]' /&gt;
                                          &lt;input type=&quot;hidden&quot; name=&quot;filename&quot; value=&quot;@item.Name&quot; /&gt;
                                          &lt;button class=&quot;btn btn-success&quot;&gt;View&lt;/button&gt;
                                      &lt;/form&gt;
                                      @*&lt;img src=&quot;~/images/pencil(1).png&quot; alt=&quot;Edit&quot;&gt;
                                      &lt;a asp-page-handler=&quot;view&quot; asp-route-id=&quot;@item.Name&quot;&gt;Edit&lt;/a&gt;*@
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;form asp-page-handler=&quot;delete&quot; method=&quot;post&quot;&gt;
                                          &lt;input asp-for=&quot;EmpID&quot; type=&quot;hidden&quot; value='@Request.Query[&quot;EmpID&quot;]' /&gt;
                                          &lt;input type=&quot;hidden&quot; name=&quot;filename&quot; value=&quot;@item.Name&quot; /&gt;
                                          &lt;button class=&quot;btn btn-danger&quot;&gt;Delete&lt;/button&gt;
                                          @*&lt;img src=&quot;~/images/icons8-delete-trash-16.png&quot; alt=&quot;Delete&quot;&gt;
          &lt;a asp-page=&quot;./Delete&quot; asp-route-id=&quot;@item.Name&quot;&gt;Delete&lt;/a&gt;*@
                                      &lt;/form&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                          }
  
                      &lt;/tbody&gt;
                  &lt;/table&gt;
              }
              @if (Model.AttachForms == null)
              {
                  &lt;div class=&quot;text-center&quot;&gt;
                      &lt;p&gt;No Files To Display&lt;/p&gt;
                  &lt;/div&gt;
              }
  </code></pre>
  <p>Attachment.cshtml.cs</p>
  <pre><code>public IActionResult OnPostView()
          {
              string filename = Request.Form[&quot;filename&quot;];
              if (filename != null)
              {
                  var Folder = EmpID.ToString();
                  string fileview = Path.Combine(_env.WebRootPath, &quot;Documents/EmployeeAttachments&quot;, Folder, filename);
                  WebClient User = new WebClient();
                  Byte[] fileBuffer = User.DownloadData(fileview);
                  if (fileBuffer != null)
                  {
                      return new FileContentResult(fileBuffer, &quot;application/ms-word&quot;);
                  }
              }
              return Page();
          }
  </code></pre>
  <p>when I click on the view button, it is downloading the file, I want to view the file in the browser.</p>
  <p>if I'm changing this code snippet</p>
  <pre><code>return new FileContentResult(fileBuffer, &quot;application/ms-word&quot;);
  </code></pre>
  <p>to</p>
  <pre><code>return new FileContentResult(fileBuffer, &quot;application/pdf&quot;);
  </code></pre>
  <p>it will be showing like this
  <a href="https://i.stack.imgur.com/IMckH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IMckH.png" alt="enter image description here" /></a></p>