SoFunction
Updated on 2025-03-07

Collection of file upload source code

namespace Wmj 

public class MyUpload 

private  postedFile=null; 
private string savePath=""; 
private string extension=""; 
private int fileLength=0; 
//Show the parameter information used by this component
public string Help 

get{ 
string helpstring; 
helpstring="<font size=3>MyUpload myUpload=new MyUpload(); //Constructor";
helpstring+="=;//Set the file to be uploaded";
helpstring+="=\"e:\\\";//Set the path to upload to the server, default c:\\";
helpstring+="=100; //Set the maximum length of uploaded files, unit k, default 1k";
helpstring+="=\"doc\";Set the extension of uploaded file, default txt";
helpstring+="=();//Start upload and display the upload result</font>";
helpstring+="<font size=3 color=red>Design By WengMingJun 2001-12-12 All Right Reserved!</font>"; 
return helpstring; 


public  PostedFile 

get 

return postedFile; 

set 

postedFile=value; 


public string SavePath 

get 

if(savePath!="") return savePath; 
return "c:\\"; 

set 

savePath=value; 


public int FileLength 

get 

if(fileLength!=0) return fileLength; 
return 1024; 

set 

fileLength=value*1024; 


public string Extension 

get 

if(extension!="") return extension; 
return "txt"; 

set 

extension=value; 


public string PathToName(string path) 

int pos=("\\"); 
return (pos+1); 

public string Upload() 

if(PostedFile!=null) 

try{ 
string fileName=PathToName(); 
if(!(Extension)) return "You must select "+Extension+" file!"; 
if(>FileLength) return "File too big!"; 
(SavePath+fileName); 
return "Upload File Successfully!"; 

catch( exc) 
{return ;} 

return "Please select a file to upload!"; 



Use csc /target:Library   to compile it into a dll for multiple calls to it later
Call example
<%@page language="C#" runat="server"%> 
<%@import namespace="Wmj"%> 
<script language="C#" runat="server"> 
void Upload(object sender,EventArgs e) 

MyUpload myUpload=new MyUpload(); 
// =; 
=; 
="e:\\"; 
=100; 
=(); 

</script> 
<form enctype="multipart/form-data" runat="server"> 
<input type="file"  runat="server"/> 
<asp:Button  Text="Upload" OnClick="Upload" runat="server"/> 
<asp:Label  runat="server"/> 
</form>