惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
U
Unit 42
aimingoo的专栏
aimingoo的专栏
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
小众软件
小众软件
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
Stack Overflow Blog
Stack Overflow Blog
博客园_首页
M
MIT News - Artificial intelligence
博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
IT之家
IT之家
C
Check Point Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
D
Docker
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News

博客园 - 小林子

jQuery技术简介 在ASP·NET中实现页面之间的传参 Remoting简介 xml简介 关于CSS XAML简介 什么是WCF 泛型的优点 COBOL语言简介 OOP是什么? C#与VB.net的不同 vss Ajax的工作原理 Ajax优点和缺点 DetailsView中编辑内容的设置内容和获取内容的方法 实现上传图片之后显示预览javaScript代码 在页面中通过地址栏传值的方法 一般后台执行类的写法 GridView的用法总结(代码收藏)
上传图片到服务器中的代码(并把图片的名字用当前时间来代替)
小林子 · 2008-04-20 · via 博客园 - 小林子

  这是用来处理图片名字的方法, 他返回一个string的类型,返回的就是要存入数据库中的路径

    /// 用来处理图片的名字,用事件作为图片的名字
    /// </summary>
    /// <returns></returns>
    private string Upload()
    {
        string strDate = DateTime.Now.ToString();
        strDate = strDate.Replace("-", "");
        strDate = strDate.Replace(":", "");
        strDate = strDate.Replace(" ", "");

        string strFileName = this.File1.PostedFile.FileName;

        int nLength = strFileName.Length - strFileName.LastIndexOf(".");
        strFileName = strDate + strFileName.Substring(strFileName.LastIndexOf("."), nLength);//取文件名
        string strPath = Server.MapPath(".") + "\\Upload\\";
        this.File1.PostedFile.SaveAs(strPath + strFileName);//上载文件
        return "Upload/" + strFileName;//返回图片的url相对路径
    }