/ * Upload file c # -1 * / file.postedfile.saveas (server.mappath ("/ temp /") file.postedfile.filename.substring (file.postedfile.filename.lastIndexof ("//") 1) );
/ * Upload file C # -2 * / using system; use system.data; use system.data.sqlclient; using ca.components; // all in component namespace
Namespace ca.components {///
/ / Define an enumeration to store the information of the file public enum file {file_size, // size file_postname, // file_sysname, file_orginname, file_path}; // Constructor PUBLIC General () {// Set in Web.Config Appsettings ["FilePath"], used to store the path to the file. Filepath = system.configuration.configurationSettings.appsettings ["filepath"];
///
String filename = datetime.now.tostring (). Replace ("," "). Replace (": ","). Replace ("-", "); string fileorginname = file.postedFile.FileName.Substring (file.postedfile.filename.lastIndexof ("//") 1); if (file.postedfile.contentLength <= 0) Return Null; string postfilename; string path = new general (). FilePath "//"; TRY {INT POS = file.postedfile.filename.lastIndexof (".") 1; postfileName = file.postedfile.filename.Substring (pos, file.postedfile.filename.Length-Pos); file.postedfile.saveas (Path FileName "." Postfilename);} catch (exception exec) {throw (exec); Doublec); Double, Double = Math.Round (file.postedfile.contentLENGTH / UNIT, 2); Arr [(int) File .File_size] = size.toString (); // File size Arr [(int) file.file_postname] = postfileName; // file type (file composite name) Arr [(int) file.file_sysname] = filename; // file system name arr [(int) file.file_orginname] = fileorginname; // File original name Arr [(int) file.file_path] = path filename "." PostFileName; // File path Return Arr; // throw (htmlutility.htmlencode));}}} / * upload file VB.NET-2 * / <% @ import namespace = "System.io"%>
Sub UploadBTN_Click (Sender As Object, E as Eventargs)
Try uploadfile.postedfile.saveas (server.mappath (path.MAppath (UPLoadFile.PostedFile.FileName)) Catch EndTrynd Sub
script>