11 回答
TA贡献1825条经验 获得超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条经验 获得超3个赞
HttpPostedFile.FileName可以获取客户端上的文件的完全限定名称,但现在的浏览器为了安全起见,有时是不会提供完整的路径,只提供文件名。
TA贡献1893条经验 获得超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 关注
- 475 浏览
添加回答
举报