11 回答

TA貢獻1825條經(jīng)驗 獲得超6個贊
1 protected void lbtnUp_Click(object sender, EventArgs e) 2 { 3 if (fuProductPhoto.HasFile) 4 { 5 if (fuProductPhoto.PostedFile.ContentLength > 100 * 1024) 6 { 7 Page.ClientScript.RegisterStartupScript(this.GetType(), "", WebUnitily.AlertUrl("照片大小不能超過100K,請重新選擇")); 8 } 9 else 10 { 11 if (fuProductPhoto.PostedFile.ContentType == "image/gif" || fuProductPhoto.PostedFile.ContentType == "image/x-png" || fuProductPhoto.PostedFile.ContentType == "image/pjpeg" || fuProductPhoto.PostedFile.ContentType == "image/bmp") 12 { 13 string strNewName = WebUnitily.GetName() + System.IO.Path.GetExtension(fuProductPhoto.FileName); 14 string strPath = Server.MapPath("~/photo/" + strNewName); 15 fuProductPhoto.PostedFile.SaveAs(strPath); 16 imgPhoto.ImageUrl = "~/photo/" + strNewName; 17 ViewState["photo"] = strNewName; 18 } 19 else 20 { 21 Page.ClientScript.RegisterStartupScript(this.GetType(), "", WebUnitily.AlertUrl("請上傳常用格式的圖片")); 22 } 23 24 } 25 } 26 else 27 { 28 Page.ClientScript.RegisterStartupScript(this.GetType(), "", WebUnitily.AlertUrl("請您選擇照片后再上傳?")); 29 } 30 }
可以共同參考一下??!

TA貢獻1946條經(jīng)驗 獲得超3個贊
HttpPostedFile.FileName可以獲取客戶端上的文件的完全限定名稱,但現(xiàn)在的瀏覽器為了安全起見,有時是不會提供完整的路徑,只提供文件名。

TA貢獻1893條經(jīng)驗 獲得超10個贊
?protected void btn_AddDocConfirm_Click(object sender, EventArgs e)
??????? {
??????????? string DocDescription = txt_DocDescription_Add.Text;
??????????? int FileSize = 0;
??????????? int UpdateUserID = Convert.ToInt32(Session["UserID"]);
??????????? string FileAlias = "User" + UpdateUserID.ToString() + "_"+DateTime.Now.ToLocalTime();
??????????? string DocName = "";
??????????? string FileType = "";
??????????? if (FileUpload_AddDoc.HasFile)
??????????? {
?????????????? FileSize= FileUpload_AddDoc.PostedFile.ContentLength;
?????????????? DocName = FileUpload_AddDoc.FileName;
?????????????? FileType =System.IO.Path.GetExtension(FileUpload_AddDoc.FileName);
??????????? }
??????????? FileAlias = FileAlias + FileType;
??????????? string CategoryID =ddl_DocCategory_Add.SelectedValue;
??????????? string UpdateTime = DateTime.Now.ToShortDateString();
??????????? string FilePath = Server.MapPath(@"~/Doc/" + FileAlias);
??????????? FileUpload_AddDoc.SaveAs(FilePath);
??????????? DataAccess da = new DataAccess(Convert.ToString(Session["ConnectString"]));
??????????? int newDocID = da.ExecSProc("Document_InUpDel", "SQLInsert", 0, txt_DocName_Add.Text, DocDescription, FilePath, FileSize, FileType, FileAlias, CategoryID, UpdateUserID, UpdateTime);
??????????? ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "closebg() ", true);
??????????? pl_DocAdd.Visible = false;
??????????? bindDocuments();
??????? }
- 11 回答
- 0 關注
- 513 瀏覽
添加回答
舉報