Using system;
Using system. Data;
Using system. Data. sqlclient;
Using Ca. components; // all are in the component namespace
Namespace ca. Components
{
/// <Summary>
/// Summary of General.
/// Release Date: Author: Raytheon
/// ThisProgramMode group http: // www. ai361.com/project/
/// Passed the test in SQL2000, win2000s +. NET + iis5
/// </Summary>
Public class General
{
Private string filepath; // file path
// Define an enumeration to store file information
Public Enum File
{
File_size, // size
File_postname ,//
File_sysname,
File_orginname,
File_path
};
// Constructor
Public General ()
{
// Set the path for storing files in Web. config ["filepath.
Filepath = system. configuration. configurationsettings. deleettings ["filepath"];
}
/// <Summary>
/// General function for uploading files. This method is static and can be called by the system at any time.
/// </Summary>
/// <Param name = "file"> the parameter is the file control object on the page. </param>
/// <Returns> </returns>
Public static string [] uploadfile (htmlinputfile file)
{
String [] arr = new string [5];
// Generate a file name through the system time. This function can be closed, but the support for long Chinese file names 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 );
}
Double unit = 1024;
Double Size = 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 suffix)
Arr [(INT) file. file_sysname] = filename; // file system name
Arr [(INT) file. file_orginname] = fileorginname; // original file name
Arr [(INT) file. file_path] = path + filename + "." + postfilename; // file path
Return arr;
// Throw (new exception (htmlutility. htmlencode (IDNO. postedfile. filename )));
}
}
}