zoukankan      html  css  js  c++  java
  • 服务器保存上载文件

    下面的代码示例演示如何将客户端上载的所有文件保存到 Web 服务器的本地磁盘上的 C:TempFiles 文件夹中。

    String TempFileName;
     HttpFileCollection MyFileCollection = Request.Files;
    
     for (int Loop1 = 0; Loop1 < MyFileCollection.Count; Loop1++)
     {
      TempFileName = "C:\TempFiles\File_" + Loop1.ToString(); MyFileCollection[Loop1].SaveAs(TempFileName); }



    下面的代码示例演示将文件流保存到相对路径Template文件夹下

    foreach (string f in Request.Files.AllKeys)
                {
                    HttpPostedFileBase file = Request.Files[f];
                    if (file != null && file.ContentLength > 0)
                    {
                        string path = Server.MapPath("~/Template/");//获取uplaod文件夹路径
                        try
                        {
                            file.SaveAs(path + file.FileName);//保存文件
                        }
                        catch (Exception e)
                        {
                            throw e;
                        }
                    }
                    else
                    {
                        //文件为空的处理
                    }
                }
  • 相关阅读:
    echart图表--雷达图表的动态数据max
    访问github个人博客时*.github.io 拒绝了我们的连接请求,错误码403
    js数组对象去重
    关于vuex的demo
    原生js实现 正方体旋转
    实现分页加载,加载更多(按钮类型),滚动加载的方式
    this指向
    记录三段式布局
    vue 动态路由 和 路由模式
    vue cli 配置反向代理
  • 原文地址:https://www.cnblogs.com/lanke0/p/5147336.html
Copyright © 2011-2022 走看看