• 大小: 33.35MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-06-22
  • 语言: 其他
  • 标签: .net  c#  asp.ne  网站  上传  

资源简介

.net实现文件上传下载功能,附件预览功能,华北理工大学综合测评管理系统功能demo之一

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class updown : System.Web.UI.Page
{
    protected void Page_Load(object sender EventArgs e)
    {

    }

    protected void Button1_Click(object sender EventArgs e)
    {
        string fullFileName = this.Upload.PostedFile.FileName;
        //从路径中截取出文件名
        string fileName = fullFileName.Substring(fullFileName.LastIndexOf(‘\\‘) + 1);
        //限定上传文件的格式
        string type = fullFileName.Substring(fullFileName.LastIndexOf(‘.‘) + 1);
        if (type == “jpg“ )
        {
            //将文件保存在服务器中根目录下的files文件夹中
            string saveFileName = Server.MapPath(“files\\“) + “\\“ + fileName;
            Upload.PostedFile.SaveAs(saveFileName);
            

            ////向数据库中存储相应通知的附件的目录
            //string id = Guid.NewGuid().ToString();
            //DateInsert di = new DateInsert();
            //di.insertDate(id fileName saveFileName);
            Response.Write(“上传成功!

“);

            //BLL.news.InsertAnnexBLL insertAnnex = new BLL.news.InsertAnnexBLL();
            //AnnexEntity annex = new AnnexEntity();     //创建附件的实体
            //annex.AnnexName = fileName;               //附件名
            //annex.AnnexContent = saveFileName;        //附件的存储路径
            //annex.NoticeId = noticeId;              //附件所属“通知”的ID在这里为已知
            //insertAnnex.InsertAnnex(annex);         //将实体存入数据库(其实就是讲实体的这些属性insert到数据库中的过程,具体BLL层和DAL层的代码这里不再多说)
        }
        else
        {
            Response.Write(“只能上传.jpg格式文件!

“);
        }
    }

    protected void Button2_Click(object sender EventArgs e)
    {
        try
        {
            string strFilePath = Server.MapPath(“~“) + “/files/0.jpg“;//服务器文件路径
            FileInfo fileInfo = new FileInfo(strFilePath);
            Response.Clear();
            Response.Charset = “GB2312“;
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.AddHeader(“Content-Disposition“ “attachment;filename=“ + Server.UrlEncode(fileInfo.Name));
            Response.AddHeader(“Content-Length“ fileInfo.Length.ToString());
            Response.ContentType = “application/x-bittorrent“;
            Response.WriteFile(fileInfo.FullName);
            Response.End();
        }
        catch (System.Threading.ThreadAbortException ex)
        {
            //不做处理
        }
        catch (Exception ex)
        {
            //做处理
        }
    }

    protected void Button3_Click(object sender EventArgs e)
    {
        Image1.ImageUrl = “../files/0.jpg“;
        popupChangeRuleImg.ShowOnPageLoad=true;
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-04-17 12:16  WebSite2\
     目录           0  2019-04-17 12:16  WebSite2\.vs\
     目录           0  2019-04-17 12:16  WebSite2\.vs\config\
     文件       83790  2019-04-17 13:08  WebSite2\.vs\config\applicationhost.config
     目录           0  2019-04-17 12:16  WebSite2\.vs\WebSite2\
     目录           0  2019-04-17 12:17  WebSite2\.vs\WebSite2\v15\
     文件       57344  2019-04-19 13:34  WebSite2\.vs\WebSite2\v15\.suo
     目录           0  2019-04-17 12:17  WebSite2\.vs\WebSite2\v15\Server\
     目录           0  2019-04-17 12:17  WebSite2\.vs\WebSite2\v15\Server\sqlite3\
     文件           0  2019-04-17 12:17  WebSite2\.vs\WebSite2\v15\Server\sqlite3\db.lock
     文件     1392640  2019-04-17 19:33  WebSite2\.vs\WebSite2\v15\Server\sqlite3\storage.ide
     文件       32768  2019-04-19 13:34  WebSite2\.vs\WebSite2\v15\Server\sqlite3\storage.ide-shm
     文件     4494952  2019-04-19 13:34  WebSite2\.vs\WebSite2\v15\Server\sqlite3\storage.ide-wal
     目录           0  2019-04-17 12:16  WebSite2\packages\
     目录           0  2019-04-17 12:16  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\
     文件        9355  2018-05-24 16:38  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\.signature.p7s
     目录           0  2019-04-17 12:16  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\
     目录           0  2019-04-17 12:16  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net45\
     文件         271  2018-05-24 13:38  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Extensions.props
     文件        5530  2018-05-24 13:38  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props
     目录           0  2019-04-17 12:16  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\
     文件         275  2018-05-24 13:38  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Extensions.props
     文件        5530  2018-05-24 13:38  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props
     目录           0  2019-04-17 12:16  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\
     目录           0  2019-04-17 12:16  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\net45\
     文件        2421  2018-05-24 13:38  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\net45\app.config.install.xdt
     文件         994  2018-05-24 13:38  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\net45\app.config.uninstall.xdt
     文件        2131  2018-05-24 13:38  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\net45\web.config.install.xdt
     文件         742  2018-05-24 13:38  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\net45\web.config.uninstall.xdt
     目录           0  2019-04-17 12:16  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\net46\
     文件        2432  2018-05-24 13:38  WebSite2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\content\net46\app.config.install.xdt
............此处省略191个文件信息

评论

共有 条评论