I'm currently working on a project (WinForms, C#, VS2012), where I need to load an InfoPath-XML file from a SharePoint (2010 I think) document library and do some sniffing around for special elements in it.
I am NOT developing on a SharePoint server, since the connection to SharePoint is only a very small portion of what the program actually does. I just plug into some SharePoint lists to pretend I'm querying a database. (I know, SharePoint lists are no database tables in a proper database sense, but that's not the point) The lists contain data vital to my program and via a web service it is quite simple to get the lists contents.
I am NOT using the SharePoint object model (SharePoint*.dll), since I don't have those and can't properly reference them, web services worked fine until now.
After querying a list I know the filename of a file stored in a document library. When I assemble the url for this file and paste it into the browser of my choice, SharePoint displays the file in its GUI as it is displayed inside InfoPath (when I paste the exact same url).
I have a copy of the xml saved locally. This I can open and process as an xml easily. When however I try to open the file directly from the server, my Stream (or FileStream) contains HTML-Code for the SharePoint site showing me my InfoPath document. Here is my code for opening:
string Path = @"awesome-correct-url";
WebRequest request = WebRequest.Create(Path);
request.UseDefaultCredentials = true; //SharePoint needs to know I am allowed to open the file
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream fs = response.GetResponseStream();
StreamReader sr = new StreamReader(fs);
string text = sr.ReadToEnd();
Console.WriteLine(text);
On reviewing what has been written to the console, I find that it is the sites HTML code.
Is there a way to convince SharePoint to give me the contents of the file rather than the nice reviewing site?