解决方案 »
- asp.net里嵌入winfrom
- 高分求:google图片搜索和adsense如何结合使用?
- 为什么FileUpload遇见中文名就没有办法通过验证控件?知情人进来湫湫~~~~
- 模仿CS的TabStrip做成的自定义控件: 不能获得View里面的自动添加的控件(内附代码)
- WEB服务器能否区分客户端的通信请求来自PC还是手机等移动设备?
- 求一小算法~~~~大家一起来帮忙帮忙。~~~
- 求代码优化!
- 同时打开连接时会抛出连接已经打开异常,怎样避免这样的问题?
- 服务器端.net的运行环境问题?
- 数据库更新时报错,必须声明变量 '@sEmail',代码见内容,求教!!!
- 制作翻转器的一些疑问
- 这个参数什么意思啊?求解,谢谢了
http://dotnet.aspx.cc/Exam/Image2Access.zip
<form id="form1" runat="server">
<div>
<table style="width: 343px">
<tr>
<td style="width: 100px">
多文件上传</td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 100px">
<asp:FileUpload ID="FileUpload1" runat="server" Width="475px" />
</td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 100px">
<asp:FileUpload ID="FileUpload2" runat="server" Width="475px" /></td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 100px">
<asp:FileUpload ID="FileUpload3" runat="server" Width="475px" /></td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 100px">
<asp:Button ID="bt_upload" runat="server" OnClick="bt_upload_Click" Text="一起上传" />
<asp:Label ID="lb_info" runat="server" ForeColor="Red" Width="448px"></asp:Label></td>
<td style="width: 100px">
</td>
</tr>
</table>
</div>
</form>
</body>
using System;
using System.Data;
using System.Configuration;
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; public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void bt_upload_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile.FileName == "" && FileUpload2.PostedFile.FileName == "" && FileUpload3.PostedFile.FileName == "")
{
this.lb_info.Text = "请选择文件!";
}
else
{
HttpFileCollection myfiles = Request.Files;
for (int i = 0; i < myfiles.Count; i++)
{
HttpPostedFile mypost = myfiles[i];
try
{
if (mypost.ContentLength > 0)
{
string filepath = mypost.FileName;//C:\Documents and Settings\Administrator\My Documents\My Pictures\20022775_m.jpg
string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);//20022775_m.jpg
string serverpath = Server.MapPath("~/images/") + filename;//C:\Inetpub\wwwroot\WebSite2\images\20022775_m.jpg
mypost.SaveAs(serverpath);
this.lb_info.Text = "上传成功!";
}
}
catch (Exception ex)
{
this.lb_info.Text = "上传发生错误!原因:" + ex.Message.ToString();
}
}
}
}
}jquery 批量上传插件Uploadify
参考
public bool DownLoadFile(string localPath, string hostURL, int byteCount, string userID, long cruuent)
{
bool result = true;
string tmpURL = hostURL;
byteCount = byteCount * 1024;
hostURL = tmpURL + "&npos=" + cruuent.ToString();
System.IO.FileStream fs;
fs = new FileStream(localPath, FileMode.OpenOrCreate);
if (cruuent > 0)
{
//偏移指针
fs.Seek(cruuent, System.IO.SeekOrigin.Current);
}
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(hostURL);
if (cruuent > 0)
{
request.AddRange(Convert.ToInt32(cruuent)); //设置Range值
} try
{
//向服务器请求,获得服务器回应数据流
System.IO.Stream ns = request.GetResponse().GetResponseStream(); byte[] nbytes = new byte[byteCount];
int nReadSize = 0;
nReadSize = ns.Read(nbytes, 0, byteCount);
while (nReadSize > 0)
{
fs.Write(nbytes, 0, nReadSize);
nReadSize = ns.Read(nbytes, 0, byteCount);
}
fs.Close();
ns.Close();
}
catch(Exception ex)
{
LOG.Error("下载" + localPath + "的时候失败!" + "原因是:" + ex.Message);
fs.Close();
result = false;
}
return result;
}
#endregion
cn.Open();
SqlDataAdapter da2 = new SqlDataAdapter("select * from myfile where id= 24 ", cn);//读出数据库中相应的数据
DataSet ds2 = new DataSet();
da2.Fill(ds2);
byte[] b2 = (byte[])ds2.Tables[0].Rows[0]["files "];
string type = (string)ds2.Tables[0].Rows[0]["type "];
Response.Clear();
string Type = checktype(type);
Response.AddHeader("Content-Disposition", "attachment; filename=下载" + type);
Response.AddHeader("Content-Length ", b2.Length.ToString());
Response.ContentType = Type;
Response.BinaryWrite(b2);
Response.End(); string FileName = ((LinkButton)sender).CommandArgument;
Response.Clear();
Response.ContentType = Type;
Response.AddHeader("Content-Disposition", "attachment;FileName= " + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8));
Response.WriteFile(FileName);
Response.End();
CS0103: 当前上下文中不存在名称“checktype”还有
Response.AddHeader("Content-Disposition", "attachment; filename=下载" + type);
中的filename 怎么来的,需要自己定义吗??