Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to send xml file in web api response.I tried this.Is that fine?

What I have tried:

public IHttpActionResult RequestDetails()
  {
      try
      {
        var result=  getPlDetail.Details();
          if (result != null)
          {
              XmlDocument xmlDoc = new XmlDocument();
              xmlDoc.Load(result);
              return Ok(xmlDoc);
          }
          else
          {
              return BadRequest();
          }
      }
      catch (Exception ex)
      {
          return BadRequest();
      }
  }
Posted
Updated 21-Jul-20 0:58am
v2
Comments
Richard MacCutchan 21-Jul-20 6:51am    
Yes, it's fine.
Member 14512875 21-Jul-20 6:58am    
thanks,but at client side I am getting {object} inside the the data .How can I access that file data at client side?

1 solution

I am not sure what you mean by
return Ok(xmlDoc);


Here, detailed reference from a CodeProject article: How to Send an XML File From a Client to a Server Via REST in a Web API C# Solution[^]

Convert XML data to JSON and return it from Web API | BinaryIntellect Knowledge Base[^]

If you return a serializable object, WebAPI will by itself send JSON or XML based on the Accept header that the client sends.
 
Share this answer
 
v3
Comments
Member 14512875 21-Jul-20 7:06am    
How can I find this file at client end?
Sandeep Mewara 21-Jul-20 9:28am    
Did you see the two urls shared? second one: http://www.binaryintellect.net/articles/7e87b1eb-b93c-4d3f-93b4-4b55e0574f4d.aspx
Member 14512875 22-Jul-20 8:03am    
At client end I am getting xml string inside the content of response what I send from my api.Is that fine?
Sandeep Mewara 22-Jul-20 8:18am    
you can DEBUG and see.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900