Search code examples
c#.netinfopath

Download infopath form as XML file using C#


I am tryign to download the InfoPath form on one of my intranet sites, say _http://ABC/XYZ/abc/PhysicsDept/Requests/Myform.xml (this is the value of variable formName) using C#. I am using the below code

using (WebClient client = new WebClient())
{
    // Set the credentials to be used for download from Sharepoint
    client.Credentials = CredentialCache.DefaultCredentials;
    client.DownloadFile(formName, "tempForm.xml");
} 

tempForm.xml is created, but sadly it contains some weird html data which is surely what i dont want. If i simply try to open the link, the value taken from formName, then i am able to easily view it as an XML, so the link is correct and working.

Can anyone please help me on this one?


Solution

  • Most likly you endup with HTML rendering of the form (XML) because corresponding form template was browser enabled.

    Add "?NoRedirect=true" query parameter (See Query Parameters for Browser-Enabled forms ) to force file download. (There should be some other way too which I can't remember right now...)