Several methods of uploading documents

xiaoxiao2021-03-06  78

/ * 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 {///

/// general's summary description. /// Date: 2002-8-8 author: Thor /// This program is a model group HTTP://WWW.AI361.COM/PROJECT/ /// in sql2000, WIN2000s .net iis5 test pass / // public class general {private string filepath; // file path

/ / 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"];

///

/// Upload file universal function, this method is static, and the system can be called. /// /// Parameter File control object /// public static string [] UPLOADFILE (HTMLINPUTFILE FILE) { String [] arr = new string [5]; // Generate file names through the system time, this feature can be closed, but the Chinese long file name is not good.

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"%>