//檢查上傳檔案不為空
if(file1.postedfile!=null)
{
stringnam=file1.postedfile.filename;
//取得檔案名(抱括路徑)裡最後一個"."的索引
inti=nam.lastindexof(".");
//取得檔案擴充名
stringnewext=nam.substring(i);
//這裡我自動根據日期和檔案大小不同為檔案命名,確定檔案名不重複
datetimenow=datetime.now;
stringnewname=now.dayofyear.tostring()+file1.postedfile.contentlength.tostring();
//儲存檔案到你所要的目錄,這裡是iis根目錄下的upload目錄.你可以改變.
//注意:我這裡用server.mappath()取目前檔案的絕對目錄.在asp.net裡""必須用""代替
file1.postedfile.saveas(server.mappath("upload"+newname+newext));
this.hyperlink1.navigateurl="upload"+newname+newext;
//得到這個檔案的相關屬性:檔案名,檔案類型,檔案大小
//fname.text=file1.postedfile.filename;
//fenc.text=file1.postedfile.contenttype;
//fsize.text=file1.postedfile.contentlength.tostring();
}