Add a <input id = "fileup" type = "file" runat = "server" name = "file1"> control on the ASPX page
A button control
In the button event of the Aspx. CS page String Filepath = "" , Fileextname = "" , Mfilename, mpath;
System. Text. stringbuilder strme = New System. Text. stringbuilder ();
If (Fileup. postedfile. filename ! = "" )
{
Filepath = Fileup. postedfile. filename;
Fileextname = Filepath. substring (filepath. lastindexof ( " . " ) + 1 );
Try
{
Mpath = Server. mappath ( " Upfile " );
// Get File Name
Mfilename = Filepath. substring (filepath. lastindexof ( " \\ " ) + 1 );
Fileup. postedfile. saveas (mpath + " / " + Mfilename );
// You must add "/" in the middle. Otherwise, the upfile folder name will be used as a part of the name of the uploaded file.
}
Catch (Exception eeee)
{
}
}
If the image is uploaded to the server and stored in the database to retrieve the path on different pages, you can save the image name to the database and put the image into a directory.
string patht = request. applicationpath + " \ businesscard/ " + request. querystring [ " strr " ]. replace ( " ' " , "" );;
image1.imageurl = patht;
request. applicationpath is the physical path of the server root directory
businesscard is the business card directory, request. querystring ["strr"]. replace ("'", ""); get the image name from the page and remove the ''added during the transfer process.