This article mainly introduces how asp.net gets the path in HTML form file, and the friends you need can refer to the following
Code as follows: #region upload files to database and server public void Fn_upfiles () { //Traverse File table cell element Httpfilecollection Files = httpcontext.current.request.files; try { for (int ifile = 0; ifile < Files. Count; ifile++) { /Check file extension name httppostedfile postedfile = files[ifile]; string filename = "";//define filename & nbsp String fileextension = "" "; filename = path.getfilename (postedfile.filename);//Get the full name of the uploaded file-file name + suffix name int index = Filename.indexof ("."); String FileType = filename.substring (index). ToLower ()//intercepting file suffix name //filetypeimg = ". /filetypeimg/"+ Hz +". gif "; guid fileguid = Guid.NewGuid ();//Generate new file name with Guid to prevent file name same string newfilename = fi Leguid.tostring ()///new filename NewFileName = newfilename + filetype;//new filename + suffix name if (postedfile.contentlength > 2097151 * 1024)//determine if larger than the upload file size in the configuration file { page.registerstartupscript ("Hint", "<script language=") JavaScript ' >alert (' Sorry your uploading resources are too big! '); Return;</script>"); return; } else { if (filename!= "")//if the filename is not empty { try { //File virtual path &nbs P 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 ("Upload resource" + fileName + "Success!" + "Server path:" + strpath); //save file to specified directory (virtual directory) Postedfile.saveas ( System.Web.HttpContext.Current.Server. MapPath ("~/upload/") + NewFileName); //page.registerstartupscript ("Hint", "<script language= ' JavaScript ' > Alert (' Upload success! '); Self.opener.location.reload (), Window.close ();</script> "); alertmsg (" Upload success! "); } } catch (Exception ex) { NR. Error.Log.LogType (ex. ToString ()); } } catch (Exception ex) { NR. Error.Log.LogType (ex. ToString ()); } } else { Response.Write ("Upload file cannot be empty!"); NR. Error.Log.LogType ("File cannot be empty!"); } } } } catch (System.Exception ex) { NR. Error.Log.LogType (ex. ToString ()); } } #endregion