日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

html表单上传图片获取路径,asp.net获取HTML表单File中的路径的方法

發(fā)布時間:2025/4/16 asp.net 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html表单上传图片获取路径,asp.net获取HTML表单File中的路径的方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

代碼如下:

#region 上傳文件到數(shù)據(jù)庫和服務器

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("提示", "alert('對不起您的上傳資源過大!');return;");

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("提示", "alert('上傳成功!');self.opener.location.reload();window.close();");

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

總結

以上是生活随笔為你收集整理的html表单上传图片获取路径,asp.net获取HTML表单File中的路径的方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。