Monday, November 8, 2010

SharePoint - 401: Unauthorized downloading Infopath file with WebClient.DownloadFile

Today, I got an "401: Unauthorized" exception when calling the WebClient.DownloadFile method to download an Infopath file from SharePoint, even if I provided the correct permissions (setting the WebClient.Credentials property).

This was because of the Infopath Forms Server feature in MOSS 2007 Enterprise edition. This feature redirects to the /_layouts/FormServer.aspx page, apparently this was resulting in an Unauthorized exception.

A workaround is to add "?NoRedirect=true" to the url, like this: http://ServerName/sites/SiteCollection/FormLibrary/Form1.xml?NoRedirect=true.

More information about some Query Parameters you can use on the /_layouts/FormServer.aspx page: http://msdn.microsoft.com/en-us/library/ms772417.aspx

7 comments:

Kevin Birdwell said...

Thanks so much! I've been struggling with this for a while and this fixed my problem. Also, you're post has a small typo; the query string key should be "NoRedirect" instead of "NonRedirect".

Knrs said...

Thx for your feedback Kevin, I fixed the typo...

pink queen said...

Hay Dear Thats a nice Blog.Nice Thinking,Hope You will be batter in your life.
Tourism & Life Style

Shakeel Sadiq said...

Really appreciate your post; been struggling with this for a few days.

Thank you very much.

Sharepoint Development said...

I like your Post very much and It is very interesting. I will use this Info to Develop the SharePoint Applications. Thanks for share this valuable Information.

nfatima said...

I really like the blog Post. Keep posting! Also a good referring source for SharePoint related updates and SharePoint migrations
http://www.dshift.com/sponline

digital certificates said...

A special thanks for this informative post. I definitely learned new stuff here I wasn't aware of !