如何打开pdf没有保存和下载选项。 [英] how to open pdf with out save and download option.
问题描述
{
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( );
}
///< summary>
///从文件中获取字节数组的函数
///
///< param name =_ FileName/>获取字节数组的文件名
///< returns>字节数组
public byte [] FileToByteArray(string _FileName)
{
byte [] _Buffer = null;
尝试
{
//打开文件阅读
System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName,System.IO.FileMode.Open,System.IO。的FileAccess 。读取);
//将文件流附加到二进制阅读器
System.IO.BinaryReader _BinaryReader = new System.IO.BinaryReader(_FileStream );
//获取文件的总字节长度
long _TotalBytes = new System.IO.FileInfo(_FileName).Length;
//将整个文件读入缓冲区
_Buffer = _BinaryReader.ReadBytes((Int32)_TotalBytes);
//System.IO.BinaryWriter _BinaryWriter = new System.IO.BinaryWriter(_FileStream);
//关闭文件阅读器
_FileStream.Close();
_FileStream.Dispose();
_BinaryReader.Close();
}
catch(异常_Exception)
{
//错误
Console.WriteLine(异常陷入过程中:{0} ,_ Exception.ToString());
}
返回_Buffer;
}
公共类EHClass
{
void ReadFile(int index)
{
// To运行此代码,替换本地计算机的有效路径
string path = @D:\ mssql2005-feature-comparison.pdf;
System.NullReferenceException文件= new System.NullReferenceException(path);
char [] buffer = new char [10];
try
{
// file.ReadBlock(buffer,index,buffer.Length);
if(file == null)
{
//休息;
返回;
}
}
catch (System.NullReferenceException e)
{
Console.WriteLine(从{0}读取错误。 Message = {1},path,e.Message);
}
// Do带缓冲的东西... ss
}
}
{
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();
}
/// <summary>
/// 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
}
}
推荐答案
请参考这里,
http://forums.asp.net/t/1918999.aspx [ ^ ]
http://bytes.com/topic/ net / answers / 941056-how-show-pdf-file-aspx-page-without-save-option [ ^ ]
Refer here,
http://forums.asp.net/t/1918999.aspx[^]
http://bytes.com/topic/net/answers/941056-how-show-pdf-file-aspx-page-without-save-option[^]
你可以找到你的解决方案使用 ASP.NET PDF Viewer用户控件Withou t安装在客户端或服务器上的Acrobat Reader [ ^ ]
You can find your solution using ASP.NET PDF Viewer User Control Without Acrobat Reader Installed on Client or Server[^]
试试这个很好的工作
try this it's woring perfectly
Response.ContentType = "application/pdf";
Context.Response.AppendHeader("Content-Disposition","inline; filename=foo.pdf");
这篇关于如何打开pdf没有保存和下载选项。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!