RSS

Downloading InfoPath XML file as XML File through C# Program

16 Jan

If you have ever tried downloading XML form from the Forms library through code you might have realized that the downloaded file is no longer XML. 

Here is the code –

using (WebClient client = new WebClient())
{
client.Credentials = CredentialCache.DefaultCredentials;
string strXMLFile = “<siteURL>” + item.Url;
string strPath = @”D:\\” + listName + “\\” + item.Title;
client.DownloadFile(strXMLFile, strPath);
}

If you try the above code then you will be presented a HTML document but not the actual XML. In order to get around this issue you just need to add the parameter ?NoRedirect=true. What this actually tells the server is not to send the information to the forms server to be formatted. This just downloads the XML as it is. If you try the NoRedirect Parameter on IE then it will ask you where to download the file.

So, my final code looks like –

using (WebClient client = new WebClient())
{
client.Credentials = CredentialCache.DefaultCredentials;
string strXMLFile = “<siteURL>” + item.Url?NoRedirect=false;
string strPath = @”D:\\” + listName + “\\” + item.Title;
client.DownloadFile(strXMLFile, strPath);
}

I hope this helps someone 🙂

Advertisements
 
Leave a comment

Posted by on January 16, 2014 in Uncategorized

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: