足球游戏_中国足彩网¥体育资讯$

asp.net获取html表单file中的路径的方法
来源:易贤网 阅读:527 次 日期:2014-10-27 09:33:54
温馨提示:易贤网小编为您整理了“asp.net获取html表单file中的路径的方法”,方便广大网友查阅!

这篇文章主要介绍了asp.net怎么获取html表单file中的路径,需要的朋友可以参考下

代码如下:

#region 上传文件到数据库和服务器

public void fn_upfiles()

{

//遍历file表单元素

httpfilecollection files = httpcontext.current.request.files;

try

{

for (int ifile = 0; ifile < files.count; ifile++)

{

//检查文件扩展名字

httppostedfile postedfile = files[ifile];

string filename = ;//定义文件名

//string fileextension = ;

filename = path.getfilename(postedfile.filename);//得到上传文件的完整名称 即文件名+后缀名

int index = filename.indexof(.);

string filetype = filename.substring(index).tolower();//截取文件后缀名

//filetypeimg = ../filetypeimg/ + hz + .gif;

guid fileguid = guid.newguid();//生成新的文件名称 以guid命名防止文件名相同

string newfilename = fileguid.tostring();//新的文件名

newfilename = newfilename + filetype;//新的文件名+后缀名

if (postedfile.contentlength > 2097151 * 1024)//判断是否大于配置文件中的上传文件大小

{

page.registerstartupscript(提示, <script language='javascript'>alert('对不起您的上传资源过大!');return;</script>);

return;

}

else

{

if (filename != )//如果文件名不为空

{

try

{

//文件虚拟路径

string strpath = system.web.httpcontext.current.server.mappath(~/upload/) + newfilename;

try

{

nrmodel.file model = new nrmodel.file();

nrbll.file bf = new nrbll.file();

guid guid1 = guid.newguid();

guid guid2 = new guid(folderid);

guid guid3 = guid.newguid();

guid guid4 = guid.newguid();

model.fileid = guid1;

model.folderid = guid2;

model.filepath = strpath;

model.filenam = filename;

model.filesize = postedfile.contentlength;

model.decription = textarea1.value.tostring();

model.createon = datetime.now;

model.createby = guid3;

model.modefyby = guid4;

if (bf.fn_addnewres(model) > 0)

{

nr.error.log.logtype(上传资源 + filename + 成功! + 服务器路径: + strpath);

//保存文件到指定目录(虚拟目录)

postedfile.saveas(system.web.httpcontext.current.server.mappath(~/upload/) + newfilename);

//page.registerstartupscript(提示, <script language='javascript'>alert('上传成功!');self.opener.location.reload();window.close();</script>);

alertmsg(上传成功!);

}

}

catch (exception ex)

{

nr.error.log.logtype(ex.tostring());

}

}

catch (exception ex)

{

nr.error.log.logtype(ex.tostring());

}

}

else

{

response.write(上传文件不能为空!);

nr.error.log.logtype(文件不能为空!);

}

}

}

}

catch (system.exception ex)

{

nr.error.log.logtype(ex.tostring());

}

}

#endregion

中国足彩网信息请查看IT技术专栏

中国足彩网信息请查看网页制作
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标