62,047
社区成员
发帖
与我相关
我的任务
分享
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
window.onload=function()
{
document.getElementById("fileupload").onchange=function()
{
document.getElementById("div1").innerHTML=this.value;
}
}
</script>
</head>
<body>
<input type="file" id="fileupload" />
<div id="div1"></div>
</body>
</html>
var fileSelect = function(fb, fileUrl) {
var file_url = fileUrl.split("\\");
var file_fullname = file_url[file_url.length - 1].split(".");
var doc_name = "";
for (i = 0; i <= file_fullname.length - 2; i++) {
if (i == file_fullname.length - 2) { doc_name += file_fullname[i]; }
else { doc_name += file_fullname[i] + "."; }
}
FileName.setValue(doc_name);
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile != null)
{
FileUpload1.Visible = true;
string StrDir = FileUpload1.PostedFile.FileName;//获取上传文件的完整路径
int myPos = StrDir.LastIndexOf("\\");//获取上传文件路径中最后一个"\"符号的位置
string strFileName = StrDir.Substring(myPos+1);//获取上传文件的文件名
TextBox1.Text = strFileName;
}
}
}