简体   繁体   中英

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?

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...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM