本站首页    管理页面    写新日志    退出

The Neurotic Fishbowl

[学习公共库]上传,删除图片(文件夹)代码
麦林 发表于 2007/6/21 17:26:45

源文件代码:       <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" class="border">         <tr valign="middle">              <td colspan="3" class="topbg" style="height: 22px"><div align="center"><strong>广告图片管理</strong></div></td>         </tr>         <tr class="tdbg">             <td height="20" colspan="3"><div align="center">                 添加广告图片: &nbsp;<asp:FileUpload ID="FileUpload1" runat="server" Width="266px" />                 &nbsp; &nbsp;                 <asp:Button ID="Button1" runat="server" Text="上传" OnClick="Button1_Click" />                 <asp:Label ID="Label1" runat="server" ForeColor="Red" Width="153px"></asp:Label></div></td>         </tr>       </table> 代码.cs文件:上传:    protected void Button1_Click(object sender, EventArgs e)    {        Boolean fileOK = false;        string path = Server.MapPath("~/AdPic/");        string url = "../AdPic/" + FileUpload1.FileName;        if (FileUpload1.HasFile)        {            string fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName.ToLower());            string[] allowedExtentions = { ".gif", ".png", ".jpg", ".jpep" };            for (int i = 0; i < allowedExtentions.Length; i++)            {                if (fileExtension == allowedExtentions[i])                {                    fileOK = true;                }            }        }        if (fileOK)        {            FileUpload1.PostedFile.SaveAs(path + FileUpload1.FileName); //添加到硬盘上文件夹            string picname = FileUpload1.FileName;            AddAdPic a = new AddAdPic();            a.InsertAdPic(picname);            this.Label1.Text = "上传成功";            GetAllPic();        }        else { this.Label1.Text = "不能上传此类型文件"; }    } 删除:    protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e)    {        int picid = int.Parse(e.Item.Cells[0].Text);        string filename = e.Item.Cells[1].Text.ToString();        AddAdPic c = new AddAdPic();        try        {            c.DelAdPic(picid);            System.IO.File.Delete(Server.MapPath("~/AdPic/") + filename); //硬盘上的删除            Response.Write("<script language=javascript>alert('删除成功!')</script>");            GetAllPic();        }        catch        {            Response.Write("<script language=javascript>alert('删除失败!')</script>");        }    }

阅读全文(4326) | 回复(0) | 编辑 | 精华

 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)
 

The Neurotic Fishbowl

.: 公告

fighting for the work!


Bloginess

«September 2025»
123456
78910111213
14151617181920
21222324252627
282930

.: 我的分类(专题)

首页(449)
文字感悟(103)
学习公共库(61)
生活体会(100)
资源收集(14)
.NET-Winform(27)
音乐文字(15)
心情小记(119)
SQL问题解决(10)


In the Bowl

.: 最新日志

C#打印代码
你看到的我是蓝色的
即将逝去的3月
这个假期
两个月过去
表名存在其他表时获取数据
条码打印
Remoting的用法
INI文件用法


.: 最新回复

回复:条码打印
回复:条码打印
回复:即将逝去的3月
回复:cookie对象使用
回复:条码打印
回复:JSP学习(字符串比较)
回复:应收应付核销规则及常见问题(续)
回复:两个月过去
回复:两个月过去


The Fishkeeper
blog名称:栗色?蓝色?
日志总数:449
评论数量:201
留言数量:37
访问次数:2260129
建立时间:2006年5月16日



Text Me

.: 留言板

签写新留言

链接完成
回:loseVC
来喽~
转转......
新年啦
对自己说
祝福
回:佑手
WO


Other Fish in the Sea

.: 链接


loseVC's BLOG
Collapsar_feel
布衣加针
C#and.Net
Kinogam Web




站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.047 second(s), page refreshed 144768491 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号