using System.IO; //引入名稱空間
//上傳方法
private void Upimage()
{
if(File1.Value!="")
string fileContentType = File1.PostedFile.ContentType;//獲取檔案型別
//判斷檔案型別.只能是 BMP GIF pjpeg swf
if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg" || fileContentType == "image/swf")
//判斷檔案大小
if (File1.PostedFile.ContentLength / 1024
string name = File1.PostedFile.FileName; // 客戶端檔案路徑
FileInfo file = new FileInfo(name);
//獲取檔名稱
//把當前時間取出,組成字串,加入檔名稱,防止重複命名
string fileName = System.DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "") + file.Name;//檔名稱
string pathss = Server.MapPath("Upimage") + "\\" + fileName;//伺服器儲存路徑
try
//上傳檔案
Label2.Text = "正在上傳,請等待...";
File1.PostedFile.SaveAs(Server.MapPath("Upimage") + "\\" +
fileName);
//把基本資訊寫進資料庫,儲存圖片在伺服器的路
cc="檔案:"+fileName+"上傳成功!";
Open();
this.Label2.Text=fileName;
this.Im2.Visible=true;
this.Im1.Visible=false;
}
catch (Exception ex)
cc = "錯誤: " + ex.Message.ToString();
this.Im1.Visible = true;
this.Im2.Visible = false;
else
cc = "對不起,檔案太大.";
cc = "請上傳正確檔案格式";
hh();
using System.IO; //引入名稱空間
//上傳方法
private void Upimage()
{
if(File1.Value!="")
{
string fileContentType = File1.PostedFile.ContentType;//獲取檔案型別
//判斷檔案型別.只能是 BMP GIF pjpeg swf
if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg" || fileContentType == "image/swf")
{
//判斷檔案大小
if (File1.PostedFile.ContentLength / 1024
{
string name = File1.PostedFile.FileName; // 客戶端檔案路徑
FileInfo file = new FileInfo(name);
//獲取檔名稱
//把當前時間取出,組成字串,加入檔名稱,防止重複命名
string fileName = System.DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "") + file.Name;//檔名稱
string pathss = Server.MapPath("Upimage") + "\\" + fileName;//伺服器儲存路徑
try
{
//上傳檔案
Label2.Text = "正在上傳,請等待...";
File1.PostedFile.SaveAs(Server.MapPath("Upimage") + "\\" +
fileName);
//把基本資訊寫進資料庫,儲存圖片在伺服器的路
cc="檔案:"+fileName+"上傳成功!";
Open();
this.Label2.Text=fileName;
this.Im2.Visible=true;
this.Im1.Visible=false;
}
catch (Exception ex)
{
cc = "錯誤: " + ex.Message.ToString();
Open();
this.Im1.Visible = true;
this.Im2.Visible = false;
}
}
else
{
cc = "對不起,檔案太大.";
Open();
this.Im1.Visible = true;
this.Im2.Visible = false;
}
}
else
{
cc = "請上傳正確檔案格式";
}
}
else
{
hh();
}
}