IE8无法取得客户端完整路径的解决办法
真受不了IE 8,,这个客户端路径也居然要设置才行,搞了蛮久原来是IE8搞的鬼
解决办法
internet选项>安全>自定义级别>将文件上载到服务器时包含本地目录路径 启用
错误原因只取得文件名,没有路径
测试代码很简单如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="upload.aspx.cs" Inherits="upload" %>
<!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="fileUpload" runat="server" />
<asp:Button ID="Button3" runat="server" Text="导入2" onclick="Button3_Click" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class upload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button3_Click(object sender, EventArgs e)
{
string name = fileUpload.PostedFile.FileName;
Response.Write(name);
//FileInfo filename = new FileInfo(name);
//string path = name.Substring(0, name.LastIndexOf("\\"));
}
}