protected void Page_Load(object sender, EventArgs e) { string userName = "user@Tenant.onmicrosoft.com"; string password = "************"; var securePassword = new SecureString(); foreach (char c in password) { securePassword.AppendChar(c); } using (var ctx = new ClientContext("https://tenant.sharepoint.com/")) { ctx.Credentials = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(userName, securePassword); Web web = ctx.Web; ctx.Load(web); ctx.ExecuteQuery(); var file = ctx.Web.GetFileByServerRelativeUrl("/Shared Documents/test.pdf"); ClientResult data = file.OpenBinaryStream(); ctx.Load(file); ctx.ExecuteQuery(); HttpContext.Current.Response.ContentType = "application/pdf"; HttpContext.Current.Response.AppendHeader("content-disposition", "inline;filename=" + file.Name); HttpContext.Current.Response.AppendHeader("content-length", data.Value.Length.ToString()); HttpContext.Current.Response.BinaryWrite(StreamToByteArray(data.Value)); HttpContext.Current.Response.Flush(); } } private byte[] StreamToByteArray(Stream input) { byte[] buffer = new byte[16 * 1024]; using (MemoryStream ms = new MemoryStream()) { int read; while ((read = input.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, read); } return ms.ToArray(); } }