午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    asp.net獲取HTML表單File中的路徑的方法
    來源:易賢網 閱讀:692 次 日期:2014-08-28 16:27:26
    溫馨提示:易賢網小編為您整理了“asp.net獲取HTML表單File中的路徑的方法”,方便廣大網友查閱!

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

    代碼如下:

    #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("提示", "<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技術專欄

    更多信息請查看網絡編程

    2025國考·省考課程試聽報名

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關于我們 | 聯(lián)系我們 | 人才招聘 | 網站聲明 | 網站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網