html5获取当前表单位置,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("提示", "");

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("提示", "");

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值