//获取文件的一些信息
private void getinfo(File f1) {
// TODO Auto-generated method stub
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日hh时mm分ss秒");
if (f1.isFile()) {//isFile()方法是测试此抽象路径名表示的文件是否是一个标准文件。
System.out.println("文件名称:" + f1.getName());
System.out.println("文件路径:" + f1.getAbsolutePath());
System.out.println("文件大小:" + f1.length()+"字节(byte)");
System.out.println("最后修改的时间是:" + sdf.format(new Date(f1.lastModified())));
} else {
System.out.println("上传成功后获取服务器的相关信息:");
System.out.println("目录名称:" + f1.getName());
System.out.println("文件路径:" + f1.getAbsolutePath());
File[] files = f1.listFiles();
System.out.println("此目录中有" + files.length + "个文件!");
}
System.out.println("_______________________________");
}
private void getinfo(File f1) {
// TODO Auto-generated method stub
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日hh时mm分ss秒");
if (f1.isFile()) {//isFile()方法是测试此抽象路径名表示的文件是否是一个标准文件。
System.out.println("文件名称:" + f1.getName());
System.out.println("文件路径:" + f1.getAbsolutePath());
System.out.println("文件大小:" + f1.length()+"字节(byte)");
System.out.println("最后修改的时间是:" + sdf.format(new Date(f1.lastModified())));
} else {
System.out.println("上传成功后获取服务器的相关信息:");
System.out.println("目录名称:" + f1.getName());
System.out.println("文件路径:" + f1.getAbsolutePath());
File[] files = f1.listFiles();
System.out.println("此目录中有" + files.length + "个文件!");
}
System.out.println("_______________________________");
}
function check()
{
var fso;
fso = new ActiveXObject("Scripting.FileSystemObject");
if( fso.FileExists("c:\\testfile.txt"))
{
alert("Exists!");
}
else
{
alert("not Exists!");
}
}
如果熟悉Ajax,你可以做个隐藏的iframe.先做一次试探提交,注意要提交到iframe里面,然后在服务器端判断是否存在。然后在回调里执行下一步的操作。
protected void Button1_Click(object sender, EventArgs e)
{
try
{
#region 判断文件大小
int intFileLength = this.FileUpload1.PostedFile.ContentLength; if (intFileLength > 50000)
{
this.Label1.Text = "文件大于50k,不能上传";
return;
}
#endregion #region 判断保存的文件夹是否存在
string strUpPath = @"upfile\" + System.DateTime.Now.ToShortDateString();// +@"\"; //文件夹不存在的时候,创建文件夹
if (!System.IO.Directory.Exists(Server.MapPath(strUpPath)))
{
System.IO.Directory.CreateDirectory(Server.MapPath(strUpPath));
} string strUrl = Server.MapPath(strUpPath + @"\" + this.FileUpload1.FileName);
#endregion //上传文件
this.FileUpload1.SaveAs(strUrl); this.Label1.Text = "文件上传成功";
Response.Write("Virtual Path is:" + strUrl); }
catch (System.Exception ex)
{
this.Label1.Text = "文件上传失败:" + ex.Message;
}
}
<div>
<asp:FileUpload ID="FileUpload1" runat="server" Width="338px" Visible =true />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="asp上传" />
<asp:Label ID="Label1" runat="server" Width="297px"></asp:Label></div>
<input type =button value = "create" onclick="dis();"/>
<INPUT class="bluebutton" id="FindFile" style="Z-INDEX: 101; LEFT: 36px;
WIDTH: 274px; POSITION: absolute; TOP: 123px; HEIGHT: 22px ;display:none"
type="file" size="26" runat="server" NAME="FindFile" onserverclick="Button1_Click" >
<INPUT type =button value = "Input上传" runat="server" onserverclick="Input_Click"/>
</form>
<SCRIPT LANGUAGE=javascript>
<!--
function checkFileExist(filename)
{
var fso;
fso = new ActiveXObject("Scripting.FileSystemObject");
return fso.FileExists(filename);
}alert(checkFileExist('C:\\boot.ini')?"Exists" : "not Exists!");
alert(checkFileExist('C:\\boot_not.ini')?"Exists" : "not Exists!");
//-->
</SCRIPT>
ie7为了什么所谓的安全性考虑,现在好像不支持客户端通过js 来控制js脚本了到服务端判断把 晚上找下很多例子