using System.IO;
string path = @"D:\accountDaoRu\";
        if (Directory.Exists(path) == false)
        {
            Directory.CreateDirectory(path);
        } if (Directory.Exists(Server.MapPath(~/upimg/hufu)) == false)//如果不存在就创建file文件夹{
Directory.CreateDirectory(Server.MapPath(~/upimg/hufu));}
//Directory.Delete(Server.MapPath(~/upimg/hufu), true);//删除文件夹以及文件夹中的子目录,文件
//判断文件的存在
if (File.Exists(Server.MapPath(~/upimg/Data.html))){
Response.Write(Yes);//存在文件}else{
Response.Write(No);
//不存在文件
File.Create(MapPath(~/upimg/Data.html));//创建该文件}
string name = GetFiles.FileName;//获取已上传文件的名字
string size = GetFiles.PostedFile.ContentLength.ToString();//获取已上传文件的大小
string type = GetFiles.PostedFile.ContentType;//获取已上传文件的MIME
string postfix = name.Substring(name.LastIndexOf(.) + 1);//获取已上传文件的后缀
string ipath = Server.MapPath(upimg) +\\+ name;//获取文件的实际路径
string fpath = Server.MapPath(upfile) + \\ + name;
string dpath = upimg\\ + name;//判断写入数据库的虚拟路径
ShowPic.Visible = true;//激活
ShowText.Visible = true;//激活
//判断文件格式
if (name == ) {
Response.Write(<scriptalert('上传文件不能为空')</script);}else{
if (postfix == jpg || postfix == gif || postfix == bmp || postfix == png){
GetFiles.SaveAs(ipath);
ShowPic.ImageUrl = dpath;
ShowText.Text = 你上传的图片名称是: + name + + 文件大小: + size + KB + + 文件类型: + type + + 存放的实际路径为: + ipath;}else{
ShowPic.Visible = false;//隐藏图片
GetFiles.SaveAs(fpath);//由于不是图片文件,因此转存在upfile这个文件夹
ShowText.Text = 你上传的文件名称是: + name + + 文件大小: + size + KB + + 文件类型: + type + + 存放的实际路径为: + fpath;}

C#判断文件和文件夹是否存在 不存在则创建的更多相关文章

  1. vc++ 判断文件或是文件夹是否存在,比较好的做法

    #include <windows.h> void main() { //文件或文件夹都可以判断,最后的\\号有无都没关系 !=GetFileAttributes("D:\\My ...

  2. 【Python备忘】python判断文件和文件夹是否存在

    python判断文件和文件夹是否存在 import os os.path.isfile('test.txt') #如果不存在就返回False os.path.exists(directory) #如果 ...

  3. 判断文件是否存在,不存在创建文件&&判断文件夹是否存在,不存在创建文件夹

    1.判断文件是否存在,不存在创建文件 File file=new File("C:\\Users\\QPING\\Desktop\\JavaScript\\2.htm"); if( ...

  4. matlab判断文件或文件夹是否存在

    当前目录中包含以下文件及文件夹: startup.m win64/ … 判断当前目录中是否存在startup.m文件 if ~exist('startup.m','file')==0    error ...

  5. JAVA之旅(二十八)——File概述,创建,删除,判断文件存在,创建文件夹,判断是否为文件/文件夹,获取信息,文件列表,文件过滤

    JAVA之旅(二十八)--File概述,创建,删除,判断文件存在,创建文件夹,判断是否为文件/文件夹,获取信息,文件列表,文件过滤 我们可以继续了,今天说下File 一.File概述 文件的操作是非常 ...

  6. c 判断文件或文件夹是否存在,多种方法, 为什么从一开始就不直接来个统一的呢?

    具体内容,请看: https://blog.csdn.net/u012494876/article/details/51204615 判断文件或文件夹是否存在,竟然有这么多方法: GetFileAtt ...

  7. Java如何判断文件或者文件夹是否在?不存在如何创建?

    Java如何判断文件或者文件夹是否在?不存在如何创建?   1. 首先明确一点的是:test.txt文件可以和test文件夹同时存在同一目录下:test文件不能和test文件夹同时存在同一目录下. 原 ...

  8. java判断给定路径或URL下的文件或文件夹是否存在?

    if (file.exists()) { 来判断这是不是一个文件. file.isDirectory() 来判断这是不是一个文件夹. 1.File testFile = new File(testFi ...

  9. Python3 判断文件和文件夹是否存在、创建文件夹

    Python3 判断文件和文件夹是否存在.创建文件夹 python中对文件.文件夹的操作需要涉及到os模块和shutil模块. 创建文件: 1) os.mknod(“test.txt”) 创建空文件  ...

  10. python判断文件和文件夹是否存在、没有则创建文件夹

    原文出处:https://www.cnblogs.com/hushaojun/p/4533241.html >>> import os >>> os.path.ex ...

随机推荐

  1. mysql 索引优化知识整理笔记

    http://blog.csdn.net/zhxp_870516/article/details/8434539 http://www.jb51.net/article/49346.htm https ...

  2. 为什么MySQL不推荐使用子查询和join

    前言: 1.对于mysql,不推荐使用子查询和join是因为本身join的效率就是硬伤,一旦数据量很大效率就很难保证,强烈推荐分别根据索引单表取数据,然后在程序里面做join,merge数据. 2.子 ...

  3. 尚硅谷springboot学习18-日志使用

    默认配置 SpringBoot默认帮我们配置好了日志 //记录器 Logger logger = LoggerFactory.getLogger(getClass()); @Test public v ...

  4. JAVAWEB 一一ibatis(框架)

    ,升级版是mybatis,在配置文件里写sql语句对字段进行CURD) jar包 sqlMapConfig <?xml version="1.0" encoding=&quo ...

  5. springboot 引入 thymeleaf 模板

    第一步pom中: <!-- 引入 thymeleaf 模板依赖 --> <dependency> <groupId>org.springframework.boot ...

  6. Working with the Dynamic Type in C#

    Working with the Dynamic Type in C# https://www.red-gate.com/simple-talk/dotnet/c-programming/workin ...

  7. 二:Recovery models(恢复模式)

    For each database that you create in SQL Server, with the exception of the system databases, you can ...

  8. 指向字符串的指针和char类型的数组

    指针数组的效率比二维字符数组的效率高 指针数组不能修改字符串字面量,而二维字符数组中的内容可以更改

  9. Kotlin系列之序列(Sequences)源码完全解析

    Kotlin系列之序列(Sequences)源码完全解析 2018年06月05日 22:04:50 mikyou 阅读数:179 标签: Kotlin序列(sequence)源码解析Androidja ...

  10. maintenance

    Maintenance Primitives Operator经常需要在包含Mesos集群的机器上执行维护任务. 大多数Mesos升级可以在不影响运行的任务的情况下完成,但是有些情况下维护可能会影响正 ...