我正在開發一個Web應用程序,因爲我需要將圖像文件和一些其他文檔存儲在數據庫中,然後我必須最好在圖像框中的網頁上顯示它們。我已經在數據庫中存儲了圖像,並且還以字節數組的形式存儲了PDF文件,並且我使用了一個通用處理程序從數據庫中獲取字節數組,然後將它們顯示在圖像框中,它對圖像工作正常但它不適用於PDF文件。如何在SQL Server中將存儲的PDF btye數組顯示在圖像框中的asp.net WebForm中?
public class ShowImage : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
Int32 imgID;
if (context.Request.QueryString["id"] != null)
imgID = Convert.ToInt32(context.Request.QueryString["id"]);
else
throw new ArgumentException("No parameter specified");
context.Response.ContentType = "image/jpeg";
byte[] buffer = ShowEmpImage(imgID);
context.Response.BinaryWrite(buffer);
}
public Stream ShowEmpImage(int empno)
{
dbClass db = new dbClass();
string sql = "SELECT imgfile FROM myFiles WHERE id = @ID";
SqlCommand cmd = new SqlCommand(sql, db.con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@ID", empno);
object img = null;
try
{
db.Connect();
img = cmd.ExecuteScalar();
}
catch
{
return null;
}
finally
{
db.Disconnect();
}
return new MemoryStream((byte[])img);
}
public bool IsReusable
{
get
{
return false;
}
}
}
請指導我如何顯示PDF文件和一些其他文件的圖像框?實際上問題是我的應用程序與現有應用程序一起運行,並且無法存儲文件的擴展名,所以我可以顯示文件的唯一方法是「將它們顯示爲圖像」,但如果它們是更好的方法,那麼可以幫助我將朋友。
所以告訴我如何顯示它與瀏覽器限制?我需要在我的網頁上顯示圖像文件或PDF文件,最好在網頁上顯示它們。 – 2012-03-05 06:41:19
@AqEeL如果你想顯示PDF的圖像*,也許[看這裏](http://stackoverflow.com/questions/1255322/create-pdf-thumbnail-with-c-sharp)。除此以外;使用'
感謝您的幫助,但它不適用於我的情況。如果你有更具體的知識然後告訴我,我將感謝 – 2012-03-05 06:56:01