title: How to download xml file in asp.net using C#
body: <p>I am using an web application <strong>asp.net with mvc3</strong>. I am new to mvc3. I am having a download button on my webpage. when i am going to click the download button ,I want to able to <strong>open that XML File</strong>.</p>
  
  <p>I have tried with some code changes in <strong>ActionResult</strong> but I didnt get the file opened. By using the below mentioned code I am getting a download popup. whenever i am going to open the file I am getting some exception as shown below. Can anyone please help me for do this? Help me to resolve this problem . :-)</p>
  
  <p>Thanks in Advance.</p>
  
  <p>My code in controller is:</p>
  
  <pre><code>public FileResult Download(string id)
  {
      string fid = Convert.ToString(id);
  
      var model = service.GetAllDefinitions().First(x =&gt; x.ID == id);
      var definitionDetails = new StatisticDefinitionModel(model);
      var definition = definitionDetails.ToXml;
  
      string fileName = definitionDetails.Name + ".xml";
      string contentType = "text/xml";
  
      return File(Encoding.Unicode.GetBytes(definition), contentType, fileName);
     }
  </code></pre>
  
  <p>The exception is:</p>
  
  <pre><code>The XML page cannot be displayed 
  Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. 
  
  
  --------------------------------------------------------------------------------
  
  A name was started with an invalid character. Error processing   resource 'file:///C:/Users/asub/Downloads/fileNamegd...
  
  &lt;
  </code></pre>