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

首頁 > 編程 > .NET > 正文

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

2024-07-10 13:27:08
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:


#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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 马关县| 阿勒泰市| 靖江市| 宝清县| 云霄县| 河池市| 九寨沟县| 吉首市| 柘城县| 绥宁县| 龙游县| 平塘县| 襄垣县| 元朗区| 鄂伦春自治旗| 合肥市| 偃师市| 上虞市| 克东县| 涞水县| 镶黄旗| 城固县| 泰来县| 济源市| 普洱| 龙泉市| 龙川县| 富蕴县| 长岛县| 南部县| 兰州市| 寻甸| 钟山县| 钟祥市| 益阳市| 石河子市| 来凤县| 彰化市| 丰台区| 唐河县| 尉氏县|