主頁面HotelPhoto.aspx前臺代碼:
- C# code
-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HotelPhoto.aspx.cs" Inherits="HotelPhoto" %>
<!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" >
<head runat="server">
<title>無標題頁</title>
<script type="text/javascript">
function OpenFileDialog()
{
var ifrForm = ifr.document.frmUpLoad;
var fileUpLoad = ifrForm.fileUpLoad;
fileUpLoad.click();
ifrForm.btnUpLoad.click();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="btnAddImage" value="新增圖片" onclick="OpenFileDialog()"/><br />
<iframe src="FileUpLoad.aspx" id="ifr" name="ifr" scrolling="no" frameborder="0"></iframe>
</div>
</form>
</body>
</html>
後臺什麼代碼都不用寫
frame裏頁面FileUpLoad.aspx前臺代碼:
- C# code
-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUpLoad.aspx.cs" Inherits="FileUpLoad" %>
<!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" >
<head runat="server">
<title>無標題頁</title>
<script type="text/javascript">
function sumbitForm()
{
document.frmUpLoad.submit();
}
</script>
</head>
<body>
<form id="frmUpLoad" runat="server">
<div>
<input type="file" id="fileUpLoad" runat="server" style="visibility:hidden" />
<input type="button" id="btnUpLoad" runat="server" style="visibility:hidden" onclick="sumbitForm()" />
<span id="spnUpLoad" runat="server" style="color:Red"></span>
</div>
</form>
</body>
</html>
frame裏頁面FileUpLoad.aspx.cs後臺代碼:
- C# code
-
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 System.Drawing.Imaging;
using DotNetTrip.Drawing;
public partial class FileUpLoad : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Files.Count == 1)
{
string filaName = this.fileUpLoad.PostedFile.FileName;
if (!string.IsNullOrEmpty(filaName))
{
this.fileUpLoad.PostedFile.SaveAs(Server.MapPath(@"Images/") + System.DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg");
}
}
}
}