Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
{ 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
///

/// <param name="_FileName" />File name to get byte array
/// <returns>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
Updated 8-Nov-13 0:48am
v2
Comments
Raajkumar.b 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

 
Share this answer
 
try this it's woring perfectly

C#
Response.ContentType = "application/pdf";
 Context.Response.AppendHeader("Content-Disposition","inline; filename=foo.pdf");
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900