Oliver -
If you code cannot use SharePoint and you are using ASP.Net you can use the following:
public static void CopyStream(Stream input, Stream output) {
byte[] buffer = new byte[8 * 1024];
int len;
while ((len = input.Read(buffer, 0, buffer.Length)) > 0) {
output.Write(buffer, 0, len);
}
}
protected void Page_Load(object sender, EventArgs e)
{
string url = "https://myserver.com/test/Shared%20Documents/mypic.jpg";
WebRequest request = WebRequest.Create(new Uri(url, UriKind.Absolute));
request.UseDefaultCredentials = true;
WebResponse response = request.GetResponse();
Stream fs = response.GetResponseStream() as Stream;
using (FileStream localfs = File.OpenWrite(@"c:\temp\aspdownloadedfile.jpg"))
{
CopyStream(fs, localfs);
}
}
If your code is located on the SharePoint server you can use the following code (add a reference to the SharePoint.dll):
public string GetFileContents(string websiteUrl)
{
string fileContentString = string.Empty;
SPSite site = new SPSite(websiteUrl);
if (site != null)
{
SPWeb web = site.OpenWeb();
if (web != null)
{
fileContentString = web.GetFileAsString(websiteUrl);
SPFile file = web.GetFile(websiteUrl);
}
else
{
Console.WriteLine("Could not open website {0}", websiteUrl);
}
site.Dispose();
}
}
return fileContentString;