asp:FileUpload 上次图片
程序员文章站
2023-02-21 21:42:10
protected void btnEdit_Click(object sender, EventArgs e) { if (txtCarPlateNumber.Text.Trim() == "") { ClientScript.RegisterStartupScript(GetType(), ..... ......
<asp:fileupload id="fileupload附件" runat="server" width="200px" />
protected void btnedit_click(object sender, eventargs e)
{
if (txtcarplatenumber.text.trim() == "")
{
clientscript.registerstartupscript(gettype(), "", "alert('请输入车牌号!');", true);
return;
}
int id = 0;
if (string.isnullorempty(request.params["id"]) == false)
{
id = int.parse(request.params["id"]);
}
modelblackwhitelist model = new modelblackwhitelist();
model.id = id;
model.carplatetype = ddlcarplatetype.selecteditem.text;
model.carplatenumber = txtcarplatenumber.text.trim();
model.company = txtcompany.text.trim();
model.bwflag = ddlbwflag.selecteditem.value;
model.operatorname = this.userlogin;
model.createdatetime = datetime.now;
string commandname = request.params["commandname"].tostring();
switch (commandname)
{
case "upd":
{
if (fileupload附件.postedfile.filename.trim().length != 0)
{
string savepath;
string filename = datetime.now.tostring("yyyymmddhhmmssms");
if (fileupload附件.hasfile && fileupload附件.postedfile.filename.contains(".jpg"))
{
savepath = server.mappath("~/upload/");//指定上传文件在服务器上的保存路径
//检查服务器上是否存在这个物理路径,如果不存在则创建
if (!system.io.directory.exists(savepath))
{
system.io.directory.createdirectory(savepath);
}
savepath = savepath + filename + ".jpg";
fileupload附件.saveas(savepath);
model.carpicpath = "/upload /" + filename + ".jpg";
}
else
{
clientscript.registerstartupscript(gettype(), "", "alert('请选择jpg图片文件!');", true);
return;
}
}
int result = sqlsugarclienthelper.sqldbconnection.updateable<modelblackwhitelist>(model).executecommand();
if (result > 0)
{
clientscript.registerstartupscript(gettype(), "", "alert('保存成功!');window.location = 'blackwhitelistmanage.aspx';", true);
}
else
{
clientscript.registerstartupscript(gettype(), "", "alert('保存失败!');", true);
}
break;
}
case "new":
{
if (fileupload附件.postedfile.filename.trim().length != 0)
{
string savepath;
string filename = datetime.now.tostring("yyyymmddhhmmssms");
if (fileupload附件.hasfile && fileupload附件.postedfile.filename.contains(".jpg"))
{
savepath = server.mappath("~/upload/bwflag/");//指定上传文件在服务器上的保存路径
//检查服务器上是否存在这个物理路径,如果不存在则创建
if (!system.io.directory.exists(savepath))
{
system.io.directory.createdirectory(savepath);
}
savepath = savepath + filename + ".jpg";
fileupload附件.saveas(savepath);
model.carpicpath = "/upload/bwflag/" + filename + ".jpg";
}
else
{
clientscript.registerstartupscript(gettype(), "", "alert('请选择jpg图片文件!');", true);
return;
}
}
int result = sqlsugarclienthelper.sqldbconnection.insertable<modelblackwhitelist>(model).executecommand();
if (result > 0)
{
clientscript.registerstartupscript(gettype(), "", "alert('保存成功!');window.location = 'blackwhitelistmanage.aspx';", true);
}
else
{
clientscript.registerstartupscript(gettype(), "", "alert('保存失败!');", true);
}
break;
}
}
}
上一篇: AjaxToolKit之Rating控件的使用方法
下一篇: Android实现可复用的筛选页面
推荐阅读
-
用asp解析图片地址,并将其保存。
-
Asp.NetCoreWebApi图片上传接口(二)集成IdentityServer4授权访问(附源码)
-
Asp.Net 将HTML中通过dom-to-image.js标签div内的内容转化为图片保存到本地
-
基于asp.net实现图片在线上传并在线裁剪功能
-
正则表达式提取网址、标题、图片等一例(.Net Asp Javascript/Js)的实现
-
一段ASP单页显示文件夹下所有图片的代码
-
asp 删除数据并同时删除图片的代码
-
asp.net中利用ashx实现图片防盗链代码
-
ASP上传图片功能的又一实现(OLE对象)
-
Asp.net_使用FileUpload控件上传文件通用方法分享