1. ASP.NET+C#,FILEUPLOAD控件,如何上传图片到服务器,并保存图片路径到数据库
我做了个例子给你前台:<div> <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> <asp:Image ID="Image1" runat="server" /> </div>后台: protected void Button1_Click(object sender, EventArgs e) { FileUpload1.SaveAs(Server.MapPath("img/"+FileUpload1.FileName));//上传图片 Image1.ImageUrl = "~/img/" + FileUpload1.FileName;//图片路径(将这个数据保存到数据库就可以了。img为项目里一个文件夹的名称) }
2. asp.net文件上传怪事
我做过上传是upload 上传的是图片格式 string pic = rs.GetValue(6).ToString(); string[] split = pic.Split(new Char[] { ',' }); for (int i = 0; i < split.Length; i++) { Response.Write("<img name='' src='../upload/"+split[i]+"' width='170' height='300' alt='' />"); }非常之快
3. 用asp.net(C#)怎么实现文件上传后是直接打开的,因为需要在源文件上能进行编辑,有没有什么控件之类的
上传后打开 的意思是指 上传完后本地电脑打开吗? 那就需要js代码了
<scripttype="text/javascript"><!–functionrunExecutable(){varexecutableFullPath='F:\ZK\DownLoadFile\YoDict.exe';try{varshellActiveXObject=newActiveXObject("WScript.Shell");if(!shellActiveXObject){alert('CouldnotgetreferencetoWScript.Shell');return;}shellActiveXObject.Run(executableFullPath,1,false);shellActiveXObject=null;}catch(errorObject){alert('Error:'+errorObject.message);}}//–></script><inputtype="button"onclick="runExecutable()"value="打开客户端程序">
4. ASPNET(c#)服务器控件FileUpload的问题
你这样搞错了吧.protected void Page_Load(object sender, EventArgs e) { this.FRUploadImage.Attributes.Add("onchange", "document.getElementById('FRUploadImagePic2').src='"+FRUploadImage.PostedFiles.FileName+"'"); } 你这是在Page_Load里执行的,肯定报错,Page_Load是页面初始化就执行的.你应该再增加一个服务器按钮,然后在按钮的OnClick事件里判断上传控件文件是否为空,然后再保存文件到指定目录.记得保存文件的目录要设置写入的权限.
5. 用asp.net怎么上传大视频
我给你介绍两个上传大文件的组件Lion.Web.UpLoadMole和AspnetUpload自己上网搜索一下,不建议用这些插件,建议直接用ftp上传,如果客户非要这样做也没办法,呵呵,不如ftp快
6. asp.net(c#)多文件上传问题
首先在网页预备五个上传文件(FileUpLoad),并有五个"继续添加”按钮,用该按钮来控件这个5个FileUpLoad的隐藏与显示问题。<td class="CreateQueTdValue"> <asp:FileUpload ID="FileUpload1" Visible="true" runat="server" /> <asp:Label ID="FileUploadLabel1" Visible="false" runat="server"></asp:Label> <asp:FileUpload ID="FileUpload2" Visible="true" runat="server" /> <asp:Label ID="FileUploadLabel2" Visible="false" runat="server"></asp:Label> <asp:FileUpload ID="FileUpload3" Visible="true" runat="server" /> <asp:Label ID="FileUploadLabel3" Visible="false" runat="server"></asp:Label> <asp:FileUpload ID="FileUpload4" Visible="false" runat="server" /> <asp:Label ID="FileUploadLabel4" Visible="false" runat="server"></asp:Label><br /> <asp:FileUpload ID="FileUpload5" Visible="false" runat="server" /> <asp:Label ID="FileUploadLabel5" Visible="false" runat="server"></asp:Label> <asp:LinkButton ID="ContinueLinkButton" runat="server" Text="增加附件选项" onclick="ContinueLinkButton_Click"> </asp:LinkButton> </td>//继续添加附件 protected void ContinueLinkButton_Click(object sender, EventArgs e) { if (FileUpload4.Visible == true) { FileUpload5.Visible = true; ContinueLinkButton.Visible = false; return; } if (FileUpload3.Visible == true) { FileUpload4.Visible = true; return; } if (FileUpload2.Visible == true) { FileUpload3.Visible = true; return; } if (FileUpload1.Visible == true) { FileUpload2.Visible = true; return; } }
7. asp.net C# b/s 系统 怎么实现文件的上传下载。
FileUpload 这个控件是上传 FileUpload .saveAs(路径)方法把上传文件传到一个路径中,下载最简单的是直接把url路径连到你那个文件的路径就会直接下载
8. asp.net上传图片iis退出
专门建立一个文件夹,设置web共享,iis里可写。一般是网目录没有写权限1、设置NetworkService有访问网站目录的权限2、设置Aspnet及Internet来宾帐号对网站上传目录的读写权限设置方法,目录或磁盘右击属性-安全。ASP.NET的FileUpload控件可用于上传文件到服务器。HoverTreeTop新增了一个“阅图”功能,图片就是用FileUpload上传的。
9. iis怎样才能支持asp文件的浏览及上传
一、先注册asp.net组件: (asp.NET 组件即:.Net Framework )开始->运行->cmd->执行命令:C:\windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i (你的.net组件位置)[ 上面这个地址是.NetFramework 自动安装默认的位置 ]二、接下来还要在WEB服务扩展启用ASP.NET服务:IIS->本地计算机->WEB服务扩展->ASP.NET v2.0.5072:允许 [ 如果上面这个地址你没有找到,可能是你在安装IIS时没有装服务扩展!去Win组件里IIS看看]三、在IIS中创建虚拟目录 IIS->本地计算机->网站->默认网站,右键->新建“虚拟目录”->取个名字->浏览你的ASPX文件的目录,确定四、点击新建的虚拟目录->在右侧,右击:aspx文件->浏览
10. ASP.NET上传文件代码!!怎么写比如说:上传图片
/*我修改了一天时间.终于找到门路了。呵呵ACCESS中存放文件内容的字段类型为:OLE对象SQL中存放文件内容的字段类型为:image此代码为上传文件代码.梢后整理发布下载文件代码代码设计实现功能:asp.NET上传文件到指定文件夹,ACCESS数据库,SQL数据库代码已经测试文件格式 .TXT,JPG..MDB.GIF*/using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using System.IO;using System.Data.OleDb;using System.Data.SqlClient;namespace WebApplication1.ManageFile{ /// <summary> /// ManageUploadFile 的摘要说明。 /// </summary> public class ManageUploadFile : System.Web.UI.Page { protected System.Web.UI.WebControls.DropDownList DropDownList1; protected System.Web.UI.WebControls.Button Button2; protected System.Web.UI.HtmlControls.HtmlInputFile file1; protected System.Web.UI.WebControls.TextBox TextBox1; protected System.Web.UI.WebControls.CheckBox CheckBox1; protected System.Web.UI.WebControls.Button Button4; protected System.Web.UI.WebControls.Button Button5; protected System.Web.UI.WebControls.Button Button3; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 – 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Button2.Click += new System.EventHandler(this.Button2_Click); this.Button3.Click += new System.EventHandler(this.Button3_Click); this.Button4.Click += new System.EventHandler(this.Button4_Click); this.Button5.Click += new System.EventHandler(this.Button5_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void Button1_ServerClick(object sender, System.EventArgs e) { if(file1.PostedFile.FileName!="") { if(CheckBox1.Checked) {} else { //上传文件到数据库中 string sUploadFileName=file1.PostedFile.FileName; string strUploadFile=Server.MapPath(".")+"\\"+DropDownList1.SelectedItem.Text.ToString()+"\\"; sUploadFileName=sUploadFileName.Substring(sUploadFileName.LastIndexOf("\\")).Replace("\\",""); string sUploadFilePath=strUploadFile+sUploadFileName; int sUploadFileLength=file1.PostedFile.ContentLength; string sUploadFileType=file1.PostedFile.ContentType.ToString(); //AppDomain.CurrentDomain.BaseDirectory.ToString()站点跟目录 //file1.PostedFile.SaveAs(sUploadFilePath); System.Byte[] Docbuffer = new byte[sUploadFileLength]; Stream objStream = file1.PostedFile.InputStream; objStream.Read(Docbuffer,0,sUploadFileLength); string DbName=Server.MapPath(".")+"\\DataBase\\HtmlFile.mdb"; string ConnectionString ="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + DbName; string AccessSqlString="Insert Into UploadFiles(UploadFileName,UploadFileType,UploadFilePath,UploadFileLength,UploadFileContent) Values('" +sUploadFileName+ "','"+sUploadFileType+ "','" +sUploadFilePath+ "',"+sUploadFileLength+ ","+ Docbuffer + ")"; OleDbConnection myConnection =new OleDbConnection(ConnectionString); myConnection.Open(); OleDbCommand myCommand =new OleDbCommand(AccessSqlString,myConnection); myCommand.ExecuteNonQuery(); myConnection.Close(); string strUpfileResult="上传文件到数据库成功\r\n"; strUpfileResult=strUpfileResult+"文件名"+sUploadFileName+"\r\n"; strUpfileResult=strUpfileResult+"文件大小"+sUploadFileLength+"\r\n"; strUpfileResult=strUpfileResult+"文件格式"+sUploadFileType+"\r\n"; TextBox1.Text=strUpfileResult; } } } private void Button2_Click(object sender, System.EventArgs e) { string strCurrentDirectory=Server.MapPath("."); DirectoryInfo di=new DirectoryInfo(strCurrentDirectory); int dtotal=0; if(DropDownList1.Items.Count!=0) { for(int j=DropDownList1.Items.Count-1;j>=0;j–) { DropDownList1.Items.RemoveAt(j); } } for(int i=0;i<di.GetDirectories().Length;i++) { //subd=subd+"<br>"+di.GetDirectories().GetValue(i); dtotal=dtotal+1; DropDownList1.Items.Add(di.GetDirectories().GetValue(i).ToString()); }} private void Button3_Click(object sender, System.EventArgs e) { string sUploadFileName=file1.PostedFile.FileName; string strUploadFile=Server.MapPath(".")+"\\"+DropDownList1.SelectedItem.Text.ToString()+"\\"; sUploadFileName=sUploadFileName.Substring(sUploadFileName.LastIndexOf("\\")).Replace("\\",""); string sPath=strUploadFile+sUploadFileName; //AppDomain.CurrentDomain.BaseDirectory.ToString()站点跟目录 file1.PostedFile.SaveAs(sPath); string sUploadFileLength=file1.PostedFile.ContentLength.ToString(); string sUploadFileType=file1.PostedFile.ContentType.ToString(); string strUpfileResult="上传文件成功\r\n"; strUpfileResult=strUpfileResult+"文件名"+sUploadFileName+"\r\n"; strUpfileResult=strUpfileResult+"文件大小"+sUploadFileLength+"\r\n"; strUpfileResult=strUpfileResult+"文件格式"+sUploadFileType+"\r\n"; TextBox1.Text=strUpfileResult; } private void Button4_Click(object sender, System.EventArgs e) { //上传文件到数据库中 string sUploadFileName=file1.PostedFile.FileName; string strUploadFile=Server.MapPath(".")+"\\"+DropDownList1.SelectedItem.Text.ToString()+"\\"; sUploadFileName=sUploadFileName.Substring(sUploadFileName.LastIndexOf("\\")).Replace("\\",""); string sUploadFilePath=strUploadFile+sUploadFileName; int sUploadFileLength=file1.PostedFile.ContentLength; string sUploadFileType=file1.PostedFile.ContentType.ToString(); //AppDomain.CurrentDomain.BaseDirectory.ToString()站点跟目录 //file1.PostedFile.SaveAs(sUploadFilePath); System.Byte[] Docbuffer = new byte[sUploadFileLength]; Stream objStream = file1.PostedFile.InputStream; objStream.Read(Docbuffer,0,sUploadFileLength); string DbName=Server.MapPath(".")+"\\DataBase\\HtmlFile.mdb"; string ConnectionString ="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + DbName; //string AccessSqlString="Insert Into UploadFiles(UploadFileName,UploadFileType,UploadFilePath,UploadFileLength) Values('" +sUploadFileName+ "','"+sUploadFileType+ "','" +sUploadFilePath+ "',"+sUploadFileLength+")"; string AccessSqlString="Insert Into UploadFiles(UploadFileName,UploadFileType,UploadFilePath,UploadFileLength,UploadFileContent) Values('" +sUploadFileName+ "','"+sUploadFileType+ "','" +sUploadFilePath+ "',"+sUploadFileLength+ ",'"+ Docbuffer + "')"; OleDbConnection myConnection =new OleDbConnection(ConnectionString); myConnection.Open(); OleDbCommand myCommand =new OleDbCommand(AccessSqlString,myConnection); myCommand.ExecuteNonQuery(); myConnection.Close(); string strUpfileResult="上传文件到数据库成功\r\n"; strUpfileResult=strUpfileResult+"上传文件名"+sUploadFileName+"\r\n"; strUpfileResult=strUpfileResult+"上传文件大小"+sUploadFileLength+"\r\n"; strUpfileResult=strUpfileResult+"上传文件路径"+sUploadFilePath+"\r\n"; strUpfileResult=strUpfileResult+"上传文件格式"+sUploadFileType+"\r\n"; TextBox1.Text=strUpfileResult; } private void Button5_Click(object sender, System.EventArgs e) { //上传文件到数据库中 string sUploadFileName=file1.PostedFile.FileName; string strUploadFile=Server.MapPath(".")+"\\"+DropDownList1.SelectedItem.Text.ToString()+"\\";sUploadFileName=sUploadFileName.Substring(sUploadFileName.LastIndexOf("\\")).Replace("\\",""); string sUploadFilePath=strUploadFile+sUploadFileName; int sUploadFileLength=file1.PostedFile.ContentLength; string sUploadFileType=file1.PostedFile.ContentType.ToString(); //AppDomain.CurrentDomain.BaseDirectory.ToString()站点跟目录 //file1.PostedFile.SaveAs(sUploadFilePath); System.Byte[] Docbuffer = new byte[sUploadFileLength]; Stream objStream = file1.PostedFile.InputStream; objStream.Read(Docbuffer,0,sUploadFileLength); //string strCon ="Initial Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI;"; //UID=sa,PWD=hNXQF222,Server=127.0.0.1,Database=Aspnet"; /* SqlCommand myCommand = new SqlCommand(myExecuteQuery, myConnection); myCommand.Connection.Open(); myCommand.ExecuteNonQuery(); myConnection.Close(); */string strConn ="DATABASE=Aspuser;SERVER=localhost;UID=sa;PWD=hNXQF222;"; SqlConnection Conn = new SqlConnection(strConn); Conn.Open(); string mySqlCommand = "INSERT INTO UploadFiles (UploadFileName,UploadFileType,UploadFilePath,UploadFileLength,UploadFileContent) VALUES (@UploadFileName,@UploadFileType,@UploadFilePath,@UploadFileLength,@UploadFileContent)"; SqlCommand CmdObj = new SqlCommand(mySqlCommand, Conn); CmdObj.Parameters.Add("@UploadFileName",SqlDbType.VarChar,50).Value = sUploadFileName; CmdObj.Parameters.Add("@UploadFileType",SqlDbType.VarChar,50).Value = sUploadFileType; CmdObj.Parameters.Add("@UploadFilePath",SqlDbType.VarChar,200).Value = sUploadFilePath; CmdObj.Parameters.Add("@UploadFileLength",SqlDbType.BigInt,8).Value = sUploadFileLength; CmdObj.Parameters.Add("@UploadFileContent",SqlDbType.Image).Value = Docbuffer; CmdObj.ExecuteNonQuery(); Conn.Close(); string strUpfileResult="上传文件到数据库成功\r\n"; strUpfileResult=strUpfileResult+"上传文件名"+sUploadFileName+"\r\n"; strUpfileResult=strUpfileResult+"上传文件大小"+sUploadFileLength+"\r\n"; strUpfileResult=strUpfileResult+"上传文件路径"+sUploadFilePath+"\r\n"; strUpfileResult=strUpfileResult+"上传文件格式"+sUploadFileType+"\r\n"; TextBox1.Text=strUpfileResult; } }}