RSS

Monthly Archives: January 2014

Downloading InfoPath XML file as XML File through C# Program

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

 

The maximum message size quota for incoming messages (65536) has been exceeded

Recently I was developing a SharePoint timer Job that references a WCF Service to retrieve some information. I was getting the following message –

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

The increase the MaxReceivedMessageSize you normally change the configuration file as follows –

<binding name=”BasicHttpBinding_MyService” maxBufferSize=”2147483647″ maxReceivedMessageSize=”2147483647″ />

But I was writing SharePoint timer Job and the timer job normally uses the owstimer.exe.config file. The file is located at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN

I was not in favor of changing the config file so I wrote the following code to set the maxReceivedMessageSize –

BasicHttpBinding binding = new BasicHttpBinding();
binding.MaxBufferSize = 2147483647;
binding.MaxReceivedMessageSize = 2147483647;
EndpointAddress remoteAddress = new EndpointAddress(“<your service URL>”);
MyService.ServiceClient service = new MyService.ServiceClient(binding, remoteAddress);
MyService.fieldResponse fieldResponse = service.<Method>;

Happy coding….

 
Leave a comment

Posted by on January 8, 2014 in Uncategorized