Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
{
byte[] Content = FileToByteArray(filename);
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline; filename=mssql2005-feature-comparison.pdf#toolbar=0");
Response.BinaryWrite(Content);
Response.End();
}
 

///
/// Function to get byte array from a file
///

/// File name to get byte array
/// Byte Array
 
public byte[] FileToByteArray(string _FileName)
{
 
byte[] _Buffer = null;
 
try
{
// Open file for reading
System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
 
// attach filestream to binary reader
System.IO.BinaryReader _BinaryReader = new System.IO.BinaryReader(_FileStream);
 
// get total byte length of the file
long _TotalBytes = new System.IO.FileInfo(_FileName).Length;
 
// read entire file into buffer
_Buffer = _BinaryReader.ReadBytes((Int32)_TotalBytes);
 
//System.IO.BinaryWriter _BinaryWriter = new System.IO.BinaryWriter(_FileStream);

// close file reader
_FileStream.Close();
_FileStream.Dispose();
_BinaryReader.Close();
}
catch (Exception _Exception)
{
// Error
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
}
 
return _Buffer;
}
public class EHClass
{
void ReadFile(int index)
{
// To run this code, substitute a valid path from your local machine
string path = @"D:\mssql2005-feature-comparison.pdf";
System.NullReferenceException file = new System.NullReferenceException(path);
char[] buffer = new char[10];
try
{
// file.ReadBlock(buffer, index, buffer.Length);
if (file == null)
{
//break;
return;
}

}
catch (System.NullReferenceException e)
{
Console.WriteLine("Error reading from {0}. Message = {1}", path, e.Message);
}
 

// Do something with buffer...ss
}
}
Posted 8-Nov-13 0:47am
Edited 8-Nov-13 0:48am
v2
Comments
Raajkumar.b at 8-Nov-13 6:58am
   
Its browser issue if u run this code in IE only it will show open or save option in google chrome it will not show
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

try this it's woring perfectly
 
Response.ContentType = "application/pdf";
 Context.Response.AppendHeader("Content-Disposition","inline; filename=foo.pdf");
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 8 Nov 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100