我采用是aspupload控件,例子上是as.net1.1,我现在用的是asp。net2.0的
原来上传代码是
<%@ Page aspCompat="True" %><%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Reflection" %>
<%@ Import Namespace="ASPUPLOADLib" %><script runat="server" LANGUAGE="C#">void Page_Load(Object Source, EventArgs E)
{
ASPUPLOADLib.IUploadManager objUpload;
objUpload = new ASPUPLOADLib.UploadManager();
int Count = objUpload.Save("c:\\upload", Missing.Value, Missing.Value); txtResult.InnerHtml = "Success. " + Count + " file(s) uploaded to c:\\upload.";
}</script><html>
<body><div id="txtResult" runat="server" style="text-align: left"/></body>
</html>
原来的上传没有问题,现在我调整了
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.Reflection;
public partial class Default3 : System.Web.UI.Page
{ protected void Page_Load(object sender, EventArgs e)
{ }
protected void b1_ServerClick(object sender, EventArgs e)
{ ASPUPLOADLib.IUploadManager objUpload;
objUpload = new ASPUPLOADLib.UploadManager(); int Count = objUpload.Save("c:\\upload", System.Reflection.Missing.Value.GetType().ToString(), System.Reflection.Missing.Value.GetType().ToString()); txtResult.InnerHtml = "Success. " + Count + " file(s) uploaded to c:\\upload."; }
}出现没有 MTS 对象上下文
原来上传代码是
<%@ Page aspCompat="True" %><%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Reflection" %>
<%@ Import Namespace="ASPUPLOADLib" %><script runat="server" LANGUAGE="C#">void Page_Load(Object Source, EventArgs E)
{
ASPUPLOADLib.IUploadManager objUpload;
objUpload = new ASPUPLOADLib.UploadManager();
int Count = objUpload.Save("c:\\upload", Missing.Value, Missing.Value); txtResult.InnerHtml = "Success. " + Count + " file(s) uploaded to c:\\upload.";
}</script><html>
<body><div id="txtResult" runat="server" style="text-align: left"/></body>
</html>
原来的上传没有问题,现在我调整了
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.Reflection;
public partial class Default3 : System.Web.UI.Page
{ protected void Page_Load(object sender, EventArgs e)
{ }
protected void b1_ServerClick(object sender, EventArgs e)
{ ASPUPLOADLib.IUploadManager objUpload;
objUpload = new ASPUPLOADLib.UploadManager(); int Count = objUpload.Save("c:\\upload", System.Reflection.Missing.Value.GetType().ToString(), System.Reflection.Missing.Value.GetType().ToString()); txtResult.InnerHtml = "Success. " + Count + " file(s) uploaded to c:\\upload."; }
}出现没有 MTS 对象上下文
解决方案 »
- 一个Dictionary里如果有相同的键,怎么把相同的键的值累加起来
- vs2010 引用命名空间的快捷键
- update 无法更新sql数据库
- 这个是为什么
- 在服务器端程序中怎么让一段JAVASCRIPT在页面的最后被执行??
- 问个老问题:限定repeater列宽的显示字数后,怎么使鼠标停在上面时把所有的内容显示出来
- datagrid中的数据如何打印
- vs.net2003菜鸟问题
- 为什么出错呢?查询引擎错误 ,如何给.xsd加参数呢
- asp.net突然不能用了!现实链接localhost------
- 小菜鸟再次出来请教,如何在 detailsView中使用fileupload更新图片,其他方法也行
- 麻烦看一下这个语句错在哪里,提示Insert into 语法错误
.NET2.0 有上传控件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
string name = FileUpload1.FileName;//上传文件名字
string size = FileUpload1.PostedFile.ContentLength.ToString();
string type = FileUpload1.PostedFile.ContentType;
string type2 = name.Substring(name.LastIndexOf(".") + 1);
string ipath = Server.MapPath("upimg") + "\\" + name;
string fpath = Server.MapPath("upfile") + "\\" + name;
string path="F:\\aaa\\"+FileUpload1.FileName;
string wpath = "upimg\\" + name;
if (type2 == "jpg" || type2 == "gif" || type2 == "bmp" || type2 == "png")
{
FileUpload1.SaveAs("F:\\aaa\\"+FileUpload1.FileName);
// Image1.ImageUrl="F:\\aaa\\"+FileUpload1.FileName;
Label1.Text = "你传图片的名字是" + name + "<br>文件大小为" + size + "<br>文件类型为" + type2 + "<br>文件路径为" + ipath;
}
SqlConnection cn = new SqlConnection("server=.;database=Northwind;uid=sa;pwd=sa");
SqlCommand cmd = new SqlCommand("insert into Image(imageName,imagepath) values('" + name + "','" + path + "')", cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{ SqlConnection cn = new SqlConnection("server=.;database=Northwind;uid=sa;pwd=sa");
SqlCommand cmd = new SqlCommand("select imageName from Image where imageID='" + Convert.ToInt32(TextBox1.Text) + "'", cn);
cn.Open();
string a = cmd.ExecuteScalar().ToString();
cn.Close();
Image1.ImageUrl = "F:\\aaa\\" + a;
}
}