The following code can retrieve a file from a SharePoint library by suing the WebClient class. You will need the credentials of the SharePoint site to create a connection. The file is retrieved as binary and stored into a local file. Eventually you get an FileStream object back pointing to the downloaded file.
byte[] binFile = null;
System.IO.FileStream fs = null;
System.IO.BinaryReader rdr = null;
string tempFileName = "C:\\tmp";
string url = http://portal.demo.nl/lists/doclib/mydoc.docx;
The following retrieves the document based on the url field and some credentials:
try
{
System.Net.WebClient client = new System.Net.WebClient();
client.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
client.DownloadFile(url, tempFileName);
System.IO.FileInfo fInfo = new System.IO.FileInfo(tempFileName);
long numBytes = fInfo.Length;
fs = new System.IO.FileStream(tempFileName, System.IO.FileMode.Open);
}
catch (System.Net.WebException ex1)
{
// catch the web exception
fs.Close();
}
catch (Exception ex)
{
// catch the default exception
fs.Close();
}