最后的50分,FreeTextBox的图片上传功能没有用。
我把改后的代码贴出来大家帮一下。
<%@ Page language="c#" %>
<script runat="server">private string NoFileMessage = "您没有选择文件。";
private string UploadSuccessMessage = "上传成功";
private string UploadFailureMessage = "上传失败。";
private string NoFolderSpecifiedMessage = "您要上传到的文件夹不存在。";
private string InvalidFileTypeMessage = "您无法上传这种类型的文件。";
private string[] AcceptedFileTypes = new string[] {"jpg","jpeg","gif","JPG","JPEG","GIF"};private string DefaultImageFolder = "Uploads"; // 默认的起始文件夹private void Page_Load(object sender, System.EventArgs e)
{
string isframe = "" + Request["frame"];if (isframe != "")
{
MainPage.Visible = true;
iframePanel.Visible = false;string FileErrorMessage = "只允许上传以下类型的文件:";
string ValidationString = ".*(";
for (int i=0;i<AcceptedFileTypes.Length; i++)
{
ValidationString += "[\\." + AcceptedFileTypes[i] + "]";
if (i < (AcceptedFileTypes.Length-1)) ValidationString += "|";
FileErrorMessage += AcceptedFileTypes[i];
if (i < (AcceptedFileTypes.Length-1)) FileErrorMessage += ", ";
}
FileValidator.ValidationExpression = ValidationString+")$";
FileValidator.ErrorMessage=FileErrorMessage;} else {}
}public void UploadImage_OnClick(object sender, EventArgs e)
{
if ( UploadFile.PostedFile.FileName.ToString().Trim() != "" )
{
string AppPath = HttpContext.Current.Request.PhysicalApplicationPath;
string AppUrl;if (Request.ApplicationPath == "/")
AppUrl = Request.ApplicationPath;
else
AppUrl = Request.ApplicationPath + "/";string ImageFileLocation = AppUrl;
ImageFileLocation = ImageFileLocation.Substring(ImageFileLocation.LastIndexOf("\\")+1);
ImageFileLocation += DefaultImageFolder;
ImageFileLocation += "/";string UploadFileName = "";
string UploadFileDestination = "";
UploadFileName = UploadFile.PostedFile.FileName;
UploadFileName = UploadFileName.Substring(UploadFileName.LastIndexOf("\\")+1);
string ImageFileExtention = UploadFileName.Substring(UploadFileName.LastIndexOf("."));
UploadFileDestination = HttpContext.Current.Request.PhysicalApplicationPath;
UploadFileDestination += DefaultImageFolder;
UploadFileDestination += "\\";
string NewFileName = DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString();
UploadFile.PostedFile.SaveAs(UploadFileDestination + NewFileName + ImageFileExtention);System.Drawing.Image image = System.Drawing.Image.FromFile(UploadFileDestination + NewFileName + ImageFileExtention);
Response.Write("<script>var arr=new Array();arr['filename']='"+ImageFileLocation+NewFileName + ImageFileExtention+"';arr['width']='"+image.Width+"';arr['height']='"+image.Height+"';window.parent.returnValue = arr;window.parent.close();<" + "/" + "script>");
}
}
private bool IsValidFileType(string FileName) {
string ext = FileName.Substring(FileName.LastIndexOf(".")+1,FileName.Length-FileName.LastIndexOf(".")-1);
for (int i=0; i<AcceptedFileTypes.Length; i++) {
if (ext == AcceptedFileTypes[i]) {
return true;}
}
return false;
}
</script>
<asp:panel id="MainPage" runat="server" visible="false">
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<META HTTP-EQUIV="Expires" CONTENT="0">
<title>插入图片</title>
<style>body {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
background: #ffffff;
width: 100%;
overflow:hidden;
border: 0;
}body,tr,td {
color: #000000;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10pt;
}div.imagespacer {
width: 120;
height: 126;
text-align: center;
float: left;
font: 10pt verdana;
margin: 5px;
overflow: hidden;
}
div.imageholder {
margin: 0px;
padding: 0px;
border: 1 solid #CCCCCC;
width: 100;
height: 100;
}div.titleholder {
font-family: ms sans serif, arial;
font-size: 8pt;
width: 100;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}</style>
<script language="javascript">
lastDiv = null;
function divClick(theDiv,filename) {
if (lastDiv) {
lastDiv.style.border = "1 solid #CCCCCC";
}
lastDiv = theDiv;
theDiv.style.border = "2 solid #316AC5";document.getElementById("FileToDelete").value = filename;}
function showimg(){
document.all.imgview.innerHTML="<img src='"+document.all.UploadFile.value+"'>";
}
function returnImage(imagename,width,height) {
var arr = new Array();
arr["filename"] = imagename;
arr["width"] = width;
arr["height"] = height;
window.parent.returnValue = arr;
window.parent.close();
}</script>
</HEAD>
<body>
<table width=100% height=100% cellpadding=0 cellspacing=0 border=0><FORM encType="multipart/form-data" runat="server" ID="Form1"><tr><td>
<div id="galleryarea" style="width=100%; height:100%; overflow: auto;">
<asp:label id="gallerymessage" runat="server"></asp:label>
<asp:panel id="GalleryPanel" runat="server"></asp:panel>
<span id="imgview"></span>
</div>
</td></tr>
<asp:Panel id="UploadPanel" runat="server">
<tr><td height=16 style="padding-left:10px;border-top: 1 solid #999999; background-color:#99ccff;"><table>
<tr>
<td valign=top><input id="UploadFile" type="file" name="UploadFile" onchange="showimg()" runat="server" style="width:300;"/></td>
<td valign=top><asp:button id="UploadImage" Text="上传" runat="server" onclick="UploadImage_OnClick" /></td>
</tr>
<tr>
<td colspan=3>
<asp:RegularExpressionValidator runat="server"
ControlToValidate="UploadFile"
id="FileValidator" display="dynamic"/>
<asp:literal id="ResultsMessage" runat="server" />
</td>
</tr></table>
<input type="hidden" id="RootImagesFolder" Value="images" runat="server" NAME="RootImagesFolder"/></td></tr>
</asp:panel>
</form>
</table>
</body>
</HTML>
</asp:panel>
<asp:panel id="iframePanel" runat="server" >
<html>
<head><title>插入图片</title></head>
<style>
body {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
background: #ffffff;
overflow:hidden;
}
</style>
<body>
<iframe style="width:100%;height:100%;border:0;" border=0 frameborder=0 src="ftb.imagegallery.aspx?frame=1&<%=Request.QueryString%>"></iframe>
</body>
</html>
</asp:panel>
我用过都是好用的,可突然间就不好用了,只能浏览图片,上传按纽就不好用了。
我把改后的代码贴出来大家帮一下。
<%@ Page language="c#" %>
<script runat="server">private string NoFileMessage = "您没有选择文件。";
private string UploadSuccessMessage = "上传成功";
private string UploadFailureMessage = "上传失败。";
private string NoFolderSpecifiedMessage = "您要上传到的文件夹不存在。";
private string InvalidFileTypeMessage = "您无法上传这种类型的文件。";
private string[] AcceptedFileTypes = new string[] {"jpg","jpeg","gif","JPG","JPEG","GIF"};private string DefaultImageFolder = "Uploads"; // 默认的起始文件夹private void Page_Load(object sender, System.EventArgs e)
{
string isframe = "" + Request["frame"];if (isframe != "")
{
MainPage.Visible = true;
iframePanel.Visible = false;string FileErrorMessage = "只允许上传以下类型的文件:";
string ValidationString = ".*(";
for (int i=0;i<AcceptedFileTypes.Length; i++)
{
ValidationString += "[\\." + AcceptedFileTypes[i] + "]";
if (i < (AcceptedFileTypes.Length-1)) ValidationString += "|";
FileErrorMessage += AcceptedFileTypes[i];
if (i < (AcceptedFileTypes.Length-1)) FileErrorMessage += ", ";
}
FileValidator.ValidationExpression = ValidationString+")$";
FileValidator.ErrorMessage=FileErrorMessage;} else {}
}public void UploadImage_OnClick(object sender, EventArgs e)
{
if ( UploadFile.PostedFile.FileName.ToString().Trim() != "" )
{
string AppPath = HttpContext.Current.Request.PhysicalApplicationPath;
string AppUrl;if (Request.ApplicationPath == "/")
AppUrl = Request.ApplicationPath;
else
AppUrl = Request.ApplicationPath + "/";string ImageFileLocation = AppUrl;
ImageFileLocation = ImageFileLocation.Substring(ImageFileLocation.LastIndexOf("\\")+1);
ImageFileLocation += DefaultImageFolder;
ImageFileLocation += "/";string UploadFileName = "";
string UploadFileDestination = "";
UploadFileName = UploadFile.PostedFile.FileName;
UploadFileName = UploadFileName.Substring(UploadFileName.LastIndexOf("\\")+1);
string ImageFileExtention = UploadFileName.Substring(UploadFileName.LastIndexOf("."));
UploadFileDestination = HttpContext.Current.Request.PhysicalApplicationPath;
UploadFileDestination += DefaultImageFolder;
UploadFileDestination += "\\";
string NewFileName = DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString();
UploadFile.PostedFile.SaveAs(UploadFileDestination + NewFileName + ImageFileExtention);System.Drawing.Image image = System.Drawing.Image.FromFile(UploadFileDestination + NewFileName + ImageFileExtention);
Response.Write("<script>var arr=new Array();arr['filename']='"+ImageFileLocation+NewFileName + ImageFileExtention+"';arr['width']='"+image.Width+"';arr['height']='"+image.Height+"';window.parent.returnValue = arr;window.parent.close();<" + "/" + "script>");
}
}
private bool IsValidFileType(string FileName) {
string ext = FileName.Substring(FileName.LastIndexOf(".")+1,FileName.Length-FileName.LastIndexOf(".")-1);
for (int i=0; i<AcceptedFileTypes.Length; i++) {
if (ext == AcceptedFileTypes[i]) {
return true;}
}
return false;
}
</script>
<asp:panel id="MainPage" runat="server" visible="false">
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<META HTTP-EQUIV="Expires" CONTENT="0">
<title>插入图片</title>
<style>body {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
background: #ffffff;
width: 100%;
overflow:hidden;
border: 0;
}body,tr,td {
color: #000000;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10pt;
}div.imagespacer {
width: 120;
height: 126;
text-align: center;
float: left;
font: 10pt verdana;
margin: 5px;
overflow: hidden;
}
div.imageholder {
margin: 0px;
padding: 0px;
border: 1 solid #CCCCCC;
width: 100;
height: 100;
}div.titleholder {
font-family: ms sans serif, arial;
font-size: 8pt;
width: 100;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}</style>
<script language="javascript">
lastDiv = null;
function divClick(theDiv,filename) {
if (lastDiv) {
lastDiv.style.border = "1 solid #CCCCCC";
}
lastDiv = theDiv;
theDiv.style.border = "2 solid #316AC5";document.getElementById("FileToDelete").value = filename;}
function showimg(){
document.all.imgview.innerHTML="<img src='"+document.all.UploadFile.value+"'>";
}
function returnImage(imagename,width,height) {
var arr = new Array();
arr["filename"] = imagename;
arr["width"] = width;
arr["height"] = height;
window.parent.returnValue = arr;
window.parent.close();
}</script>
</HEAD>
<body>
<table width=100% height=100% cellpadding=0 cellspacing=0 border=0><FORM encType="multipart/form-data" runat="server" ID="Form1"><tr><td>
<div id="galleryarea" style="width=100%; height:100%; overflow: auto;">
<asp:label id="gallerymessage" runat="server"></asp:label>
<asp:panel id="GalleryPanel" runat="server"></asp:panel>
<span id="imgview"></span>
</div>
</td></tr>
<asp:Panel id="UploadPanel" runat="server">
<tr><td height=16 style="padding-left:10px;border-top: 1 solid #999999; background-color:#99ccff;"><table>
<tr>
<td valign=top><input id="UploadFile" type="file" name="UploadFile" onchange="showimg()" runat="server" style="width:300;"/></td>
<td valign=top><asp:button id="UploadImage" Text="上传" runat="server" onclick="UploadImage_OnClick" /></td>
</tr>
<tr>
<td colspan=3>
<asp:RegularExpressionValidator runat="server"
ControlToValidate="UploadFile"
id="FileValidator" display="dynamic"/>
<asp:literal id="ResultsMessage" runat="server" />
</td>
</tr></table>
<input type="hidden" id="RootImagesFolder" Value="images" runat="server" NAME="RootImagesFolder"/></td></tr>
</asp:panel>
</form>
</table>
</body>
</HTML>
</asp:panel>
<asp:panel id="iframePanel" runat="server" >
<html>
<head><title>插入图片</title></head>
<style>
body {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
background: #ffffff;
overflow:hidden;
}
</style>
<body>
<iframe style="width:100%;height:100%;border:0;" border=0 frameborder=0 src="ftb.imagegallery.aspx?frame=1&<%=Request.QueryString%>"></iframe>
</body>
</html>
</asp:panel>
我用过都是好用的,可突然间就不好用了,只能浏览图片,上传按纽就不好用了。
解决方案 »
- form验证后,如何在后台取得当前用户ID
- 很奇怪的问题,生成静态页面汉字变乱码了
- 限制textbox只能输入固定字节
- ? 哥哥姐姐们c# treeview 中单击结点使其结点图片改变就像CSDN上左边的树一样 [.NET就是这个网页的效果http://community.csdn.net/
- 一刷新就像死机了一样
- 请教一个ASP.NET链接mysql时汉字编码的问题~
- asp.net制作的网页,如何实现登录保留(关闭网页后失效,一天失效,一个月失效)等功能
- textbox如何能作成输入ip地址的那种?
- DataSet的小问题
- 大哥们你们一定会的,,快来救命啦!!!!!!在线等待!!
- 大家做web开发时都使用什么样的版本控制工具?
- ExecuteNonQuery执行存储过程的返回值是什么?
下载地址如下:
http://ewebeditor.webasp.net/download.asp
FreeTextBox 1.6.3 (中文版)
可以传文件