回复 12楼AvoCaDolol的帖子
换了位置还是报一样的错误,以下是例子源码(主要想实现删除文件中的某一页)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Leadtools.Web.Controls;
using Leadtools.Codecs;
using System.IO;
public partial class DocumentCleanDemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
#if LEADTOOLS_V175_OR_LATER
Support.SetLicense();
#else
Support.Unlock();
#endif // #if LEADTOOLS_V175_OR_LATER
//Check if Kernel has expired
if (Leadtools.RasterSupport.KernelExpired)
{
string msg = "Your license file is missing, invalid or expired. LEADTOOLS will not function. Please contact LEAD Sales for information on obtaining a valid license.";
Page.ClientScript.RegisterStartupScript(this.GetType(), "KernalExpiredMessage", "alert('" + msg + "')", true);
return;
}
//// Load RasterCodecs options from the configuration file
//if (ConfigurationManager.AppSettings["RasterPdfInitialPath"] != null)
//{
// string pdfInitialPath = ConfigurationManager.AppSettings["RasterPdfInitialPath"];
// if (!string.IsNullOrEmpty(pdfInitialPath))
// {
// // Setup default RasterCodecs options, these options are per thread
// // and will be used by any RasterCodecs object created after this
// using (RasterCodecs codecs = new RasterCodecs())
// {
// codecs.Options.Pdf.InitialPath = pdfInitialPath;
// }
// }
//}
//Load_File(@"Resources\Ocr.tif");
get_upload_file();
}
}
private void get_upload_file()
{
string dirPath = Server.MapPath("~/upload/");
if (Directory.Exists(dirPath))
{
//获得目录信息
DirectoryInfo dir = new DirectoryInfo(dirPath);
//获得目录文件列表
FileInfo[] files = dir.GetFiles("*.*");
string[] fileNames = new string[files.Length];
//临时数据表
DataTable dt = new DataTable();
dt.Columns.Add("file_name");
foreach (FileInfo fileInfo in files)
{
DataRow dr = dt.NewRow();
dr["file_name"] = fileInfo.Name;
dt.Rows.Add(dr);
}
Repeater1.DataSource = dt;
Repeater1.DataBind();
if (hid_file_path.Value == string.Empty && dt.Rows.Count > 0)
Load_File(@"upload\" + dt.Rows[0][0]);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
bool fileOK = false;
string path = Server.MapPath("~/upload/");
if (!System.IO.Directory.Exists(path))
System.IO.Directory.CreateDirectory(path);
if (FileUpload1.HasFile)
{
String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions = { ".gif", ".png", ".bmp", ".jpg", ".pdf", ".tif", ".tiff", ".doc", ".docx", ".txt", ".ppt", ".pptx", ".jbg", ".cmp", ".xlsx", ".xls" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions)
{
fileOK = true;
}
}
}
if (fileOK)
{
try
{
string file_name = DateTime.Now.ToString("yyyyMMddHHmmssfff") + FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf("."));
FileUpload1.SaveAs(path + file_name);
get_upload_file();
Load_File(@"upload\" + file_name);
LabMessage1.Text = "文件上传成功.";
}
catch
{
LabMessage1.Text = "文件上传失败.";
}
}
else
{
LabMessage1.Text = "该类型文件无法上传.";
}
}
static string sel_file = "";
private void Load_File(string file_path)
{
using (RasterCodecs codecs = new RasterCodecs())
{
CodecsImageInfo info = codecs.GetInformation(WebThumbnailViewer1.Page.MapPath(file_path), true);
sel_file = file_path;
WebThumbnailViewer1.Clear();
if (info.TotalPages > 1)
{
string thumbText = string.Empty;
for (int i = 0; i < info.TotalPages; i++)
{
thumbText = string.Format("age{0}", i + 1);
WebThumbnailViewer1.Add(file_path, i + 1, i + 1, thumbText);
}
}
else
{
WebThumbnailViewer1.Add(file_path, 1, 1, "age1");
}
}
hid_file_path.Value = file_path;
WebThumbnailViewer1.SelectedIndex = 0;
WebImageViewer1.UseDpi = true;
WebImageViewer1.MouseInteractiveMode.LeftButton = ImageViewerMouseInteractiveMode.Pan;
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
Label lab_file = (Label)e.Item.FindControl("lab_file");
if (lab_file != null)
Load_File(@"upload\" + lab_file.Text);
}
protected void img_del_Click(object sender, ImageClickEventArgs e)
{
if (WebThumbnailViewer1.SelectedIndex >= 0)
{
WebThumbnailViewer1.Remove(WebThumbnailViewer1.SelectedIndex, WebThumbnailViewer1.SelectedIndex);
if (sel_file.Substring(sel_file.LastIndexOf(".") + 1).ToLower() == "pdf")
{
Leadtools.Pdf.PDFFile pdf_file = new Leadtools.Pdf.PDFFile(WebThumbnailViewer1.Page.MapPath(sel_file));
pdf_file.DeletePages(WebThumbnailViewer1.SelectedIndex, WebThumbnailViewer1.SelectedIndex, WebThumbnailViewer1.Page.MapPath(sel_file));
}
else
{
using (RasterCodecs codecs = new RasterCodecs())
{
codecs.DeletePage(WebThumbnailViewer1.Page.MapPath(sel_file), WebThumbnailViewer1.SelectedIndex + 1);
//using (Leadtools.RasterImage image = codecs.Load(WebThumbnailViewer1.Page.MapPath(sel_file)))
//{
// codecs.Save(image, WebThumbnailViewer1.Page.MapPath(sel_file), image.OriginalFormat, 0);
//}
}
}
}
}
}
前台源码:
<%@ Page Language="C#" AutoEventWireup="true" Inherits="DocumentCleanDemo" CodeBehind="DocumentCleanDemo.aspx.cs" %>
<%@ Register Assembly="Leadtools.Web" Namespace="Leadtools.Web.Controls" TagPrefix="ltwf" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="robots" content="index, follow" />
<title>Document Clean Demo</title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<link href="Resources/css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="Resources/DocumentCleanButtons.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="container">
<center>
<table cellpadding="0" cellspacing="0" border="0" style="border-color: White; width: 1200px">
<tr>
<td>
</td>
<td colspan="2" style="border: 0; padding-top: 20px; padding-bottom: 10px; font-size: large;">
<asp:FileUpload ID="FileUpload1" runat="server" Width="500px" Height="25px" />&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" />&nbsp;&nbsp;
<aspabel ID="LabMessage1" runat="server" ForeColor="red"/>
</td>
</tr>
<tr>
<td rowspan="3" align="center" valign="top" style="width: 200px; height:800px;">
<div class="toolbar" style="width: 95%; height: 100%; padding-top:10px;">
<asp:Repeater ID="Repeater1" runat="server" EnableViewState="true" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<div style="margin-bottom: 10px;" onmouseover="c=this.style.backgroundColor;this.style.backgroundColor='#FFFFFF';" onmouseout="this.style.backgroundColor=c;">
<asp:ImageButton ID="img_file" CommandName='<%# Eval("file_name") %>' runat="server" ImageUrl="/resources/image_flag.jpg" Width="50px" /><br />
<aspabel ID="lab_file" runat="server" Text='<%# Eval("file_name") %>'></aspabel>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</td>
<td colspan="2" valign="top" style="border: 0">
<ltwf:WebThumbnailViewer ID="WebThumbnailViewer1" runat="server" BorderStyle="Solid"
BorderWidth="1px" Height="160px" Width="1000px" ViewerID="WebImageViewer1" VerticalAlignMode="Center"
ThumbStyle-HoverBackColor="#D0D0D0" SelectedThumbStyle-BackColor="DarkRed" SelectedThumbStyle-HoverBackColor="Red"
BackColor="White" />
</td>
</tr>
<tr>
<td colspan="2" style="border: 0;">
<div id="infoBar" style="width: 1000px; background-color: Gray; border: 0;">
<%--<h1>Test</h1>--%>
<div id="zoom" class="section" style="border: 0;">
<%--<label>age Display Controls</label>--%>
<a id="btnZoomIn" title="Zoom In"></a>
<a id="btnZoomOut" title="Zoom Out"></a>
<a id="btnFit" title="Fit"></a>
<a id="btnFitWidth" title="Fit Width"></a>
<a id="btnView1to1" title="Full View"></a>
<a id="btnPan" title="change the mouse pointer to Pan"></a>
<a title="Delete Page"><asp:ImageButton ID="img_del" runat="server" ImageUrl="/resources/delete.png" Height="20px" Width="20px" onclick="img_del_Click" /></a>
</div>
</div>
</td>
</tr>
<tr>
<td align="center" valign="top" style="border: 0; width: 900px;">
<ltwf:WebImageViewer ID="WebImageViewer1" runat="server" BorderStyle="Solid" BorderWidth="1px"
Height="650px" Width="900px" HorizontalAlignMode="Center" VerticalAlignMode="Center"
ImageFrameSize="1" DropShadowSize="1" />
</td>
<td align="center" valign="top" style="border: 0; width: 100px;">
<div id="toolbar" class="toolbar" style="float: right;">
<a id="btnRotateLeft90" title="Rotate Left 90 degrees" style="cursor: pointer"></a>
<a id="btnRotateRight" title="Rotate Right 90 degrees" style="cursor: pointer"></a>
<a id="btnFlipHor" title="Flip Horizontal" style="cursor: pointer"></a>
<a id="btnFlipVer" title="Flip Vertical" style="cursor: pointer"></a>
<a id="btnResetImage" title="Reload the original page." style="cursor: pointer"></a>
</div>
</td>
</tr>
</table>
</center>
</div>
<div style=" display:none;">
<asp:HiddenField ID="hid_file_path" runat="server" />
</div>
<script type="text/javascript">
function btnResetImage_onclick() {
var index = WebThumbnailViewer1.getSelectedIndex();
var hid_file_path = document.getElementById("<%=hid_file_path.ClientID%>");
if (hid_file_path != null)
WebImageViewer1.OpenImageUrl(hid_file_path.value, index);
else
WebImageViewer1.OpenImageUrl("Resources\\DocCleanImages.tif", index);
}
</script>
</form>
</body>
</html> |