读书人

自定义控件实现上传图片解决方法

发布时间: 2012-04-09 13:41:25 作者: rapoo

自定义控件实现上传图片
利用自定义控件 实现上传图片 并把上传地址保存数据库里,最好源码。

[解决办法]
用户控件
public string SaveAttach()
{
HttpFileCollection Files = HttpContext.Current.Request.Files;
for (int i = 0; i < Files.Count; i++)
{
HttpPostedFile PostedFile = Files[i];
if (PostedFile.ContentLength > 0)
{
string FileName = PostedFile.FileName;
string AttachExt = FileName.Substring(FileName.LastIndexOf(".") + 1);
int TotalSize = PostedFile.ContentLength;
}
}
页面调用attach1.SaveAttach();
[解决办法]
ASP.NET JQuery无刷新上传附件示例

C# code
protected void btnSubmit_Click(object sender, EventArgs e)    {        lblOldAddress.Text += "<br />"; //换行        lblNewAddress.Text += "<br />";        HttpFileCollection hfc = Request.Files;        for (int i = 0; i < hfc.Count; i++)        {            HttpPostedFile hpf = hfc[i];            if (hpf.ContentLength > 0)            {                string oldAddress = hpf.FileName;                string newAddress = Server.MapPath("file\\") + System.IO.Path.GetFileName(oldAddress);                hpf.SaveAs(newAddress);            }         }    }
[解决办法]
B/S 的?最好去网上搜索NEATUPLOAD这个组件,有源码,附带JS的源码也有,上传文件,也可以上传大文件,还带进度条,这个组件的实例看懂了可以学习很多知识。
http://www.pudn.com/downloads161/sourcecode/windows/dotnet/detail732798.html

读书人网 >C#

热点推荐