国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTML > 正文

asp.net獲取HTML表單File中的路徑的方法

2020-03-24 16:14:35
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了asp.net怎么獲取HTML表單File中的路徑,需要的朋友可以參考下

代碼如下:#region 上傳文件到數據庫和服務器html' target='_blank'>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

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 敖汉旗| 格尔木市| 武平县| 巴彦淖尔市| 子洲县| 巴里| 新和县| 大竹县| 黄山市| 荥经县| 依兰县| 西林县| 科尔| 藁城市| 乌兰浩特市| 武胜县| 沙湾县| 高碑店市| 南乐县| 内黄县| 独山县| 临澧县| 永吉县| 景谷| 吴堡县| 涡阳县| 彩票| 广元市| 紫云| 新巴尔虎右旗| 海淀区| 永康市| 中山市| 泊头市| 长宁区| 海丰县| 彭州市| 哈尔滨市| 大田县| 南开区| 菏泽市|