请问该如何解决这个问题,谢谢.我用的是以下代码,上传EXCEL文件.
private Boolean SaveImages()
{
///'遍历File表单元素
HttpFileCollection files = HttpContext.Current.Request.Files; /// '状态信息
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
strMsg.Append("上传的文件分别是:<hr color=red>");
try
{
for(int iFile = 0; iFile < files.Count; iFile++)
{
///'检查文件扩展名字
HttpPostedFile postedFile = files[iFile];
string fileName, fileExtension;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
fileExtension = System.IO.Path.GetExtension(fileName);
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
strMsg.Append("上传文件的文件名:" + fileName + "<br>");
strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>");
///'可根据扩展名字的不同保存到不同的文件夹
///注意:可能要修改你的文件夹的匿名写入权限。
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName);
}
}
Label1.Text = strMsg.ToString();
return true;
}
catch(System.Exception Ex)
{
Label1.Text = Ex.Message;
return false;
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
string myConnectString = "Server=localhost;Database=pubs;uid=sa;pwd=;";
SqlConnection objConnection = new SqlConnection(myConnectString);
OleDbConnection aa=new OleDbConnection();
string path=System.Web.HttpContext.Current.Server.MapPath("images/ee.xls");//excel的文件名 aa.ConnectionString="Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + path + ";Extended Properties=Excel 8.0";
OleDbDataAdapter a=new OleDbDataAdapter("select * from [mm$]",aa);// select 语句的写法.
DataSet ds=new DataSet();
a.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
Button2.Visible=true;
}
private Boolean SaveImages()
{
///'遍历File表单元素
HttpFileCollection files = HttpContext.Current.Request.Files; /// '状态信息
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
strMsg.Append("上传的文件分别是:<hr color=red>");
try
{
for(int iFile = 0; iFile < files.Count; iFile++)
{
///'检查文件扩展名字
HttpPostedFile postedFile = files[iFile];
string fileName, fileExtension;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
fileExtension = System.IO.Path.GetExtension(fileName);
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
strMsg.Append("上传文件的文件名:" + fileName + "<br>");
strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>");
///'可根据扩展名字的不同保存到不同的文件夹
///注意:可能要修改你的文件夹的匿名写入权限。
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName);
}
}
Label1.Text = strMsg.ToString();
return true;
}
catch(System.Exception Ex)
{
Label1.Text = Ex.Message;
return false;
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
string myConnectString = "Server=localhost;Database=pubs;uid=sa;pwd=;";
SqlConnection objConnection = new SqlConnection(myConnectString);
OleDbConnection aa=new OleDbConnection();
string path=System.Web.HttpContext.Current.Server.MapPath("images/ee.xls");//excel的文件名 aa.ConnectionString="Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + path + ";Extended Properties=Excel 8.0";
OleDbDataAdapter a=new OleDbDataAdapter("select * from [mm$]",aa);// select 语句的写法.
DataSet ds=new DataSet();
a.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
Button2.Visible=true;
}
解决方案 »
- ASTreeView(免费树控件) 1.5.8 发布新版本啦
- sqlserver2005 数据库存储过程加密后怎么解密
- 用asp.net的mvc显示员工信息列表(在表格中显示员工列表)
- dorpdownlist下拉列表绑定SQL记录集问题.解决速度上分!在线等!急!
- Application_Start为什么是首次访问aspx页面之后才执行?
- 关于GRIDVIEW的删除,编辑,和选择的问题
- 关于asp.net使用socket的问题
- 请问javascript代码段怎么能放到aspx.cs中
- VS 2008 的Asp.net应用程序是什么意思?
- 帮忙找错误阿,痛苦ing...........
- 偶想开发一个ie插件,象google搜索工具栏那样子的一个东东,哪位老大给些资料啊?谢谢!
- 我的.net的程序本来好好的,现在为什么登陆button不起作用了?
cvs还是htmlwrite?