在实际开发中,如果用的文件名不能确定位置。或名字。可以使用GUID类来命名函数。Guid 结构标识全局唯一标示符。其NewGuid结构可以初始化一个新历。该方法语法格式如下:

public static Guid NewGuid();

return: 初始化后的实例。

源码:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data; using System.Drawing;

using System.Linq; using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.IO;

namespace WindowsFormsApplication47

{     public partial class Form1 : Form

{         public Form1()

{             InitializeComponent();         }

private void button2_Click(object sender, EventArgs e)

{             FolderBrowserDialog p_folderbrowserdialog = new FolderBrowserDialog();

if(p_folderbrowserdialog .ShowDialog ()==DialogResult.OK )

{                 File.Create(p_folderbrowserdialog.SelectedPath + "\\" + Guid.NewGuid().ToString() + ".txt");             }         }

private void button1_Click(object sender, EventArgs e)

{             FolderBrowserDialog p_folderbrowserdialog = new FolderBrowserDialog();

if(p_folderbrowserdialog .ShowDialog ()==DialogResult.OK )

{                 Directory.CreateDirectory(p_folderbrowserdialog.SelectedPath + "\\" + Guid.NewGuid().ToString());             }         }     } }

system.io.file创建的更多相关文章

  1. 详解C#中System.IO.File类和System.IO.FileInfo类的用法

    System.IO.File类和System.IO.FileInfo类主要提供有关文件的各种操作,在使用时需要引用System.IO命名空间.下面通过程序实例来介绍其主要属性和方法. (1) 文件打开 ...

  2. System.IO.File类和System.IO.FileInfo类

    1.System.IO.File类 ※文件create, copy,move,SetAttributes,open,exists ※由于File.Create方法默认向所有用户授予对新文件的完全读写. ...

  3. System.IO.File.Create 不会自动释放,一定要Dispose

    这样会导致W3P进程一直占用这个文件 System.IO.File.Create(HttpContext.Current.Server.MapPath(strName)) 最好加上Dispose Sy ...

  4. IIS目录下文件共享后System.IO.File.Exists返回false

    场景:在iis目录下,因为特殊需要共享一个文件夹,给到其他的技术人员访问,突然发现小小的操作,搞“大”了,使用 string path = Server.MapPath("~/file/te ...

  5. System.IO.File.WriteAllText("log.txt", "dddd");

    System.IO.File.WriteAllText("log.txt", "dddd");

  6. 关于 System.IO.File.Exists 需要注意的事项

    各位:   .NET Framework 本省在设计的时候,他对于异常没有完全做到抛出,这样可能会有很多意想不到的问题.   比如 你在asp.net 应用程序中判断文件是否存在,这个文件可能是一个共 ...

  7. C# System.IO.File

    using System; using System.IO; class Test { public static void Main() { string path = @"c:\temp ...

  8. 未处理的异常:system.io.file load exception:无法加载文件或程序集“ 。。。。 找到的程序集的清单定义与程序集引用不匹配。

    问题描述: 添加控制器的时候,突然就报了这个错: Unhandled Exception: System.IO.FileLoadException: Could not load file or as ...

  9. 安卓上为什么不能用system.io.file读取streammingAssets目录下的文件

    首先,看文档: Streaming Assets   Most assets in Unity are combined into the project when it is built. Howe ...

随机推荐

  1. Probability theory

    1.Probability mass functions (pmf) and Probability density functions (pdf) pmf 和 pdf 类似,但不同之处在于所适用的分 ...

  2. 程序员眼里IE浏览器是什么样的

    主流浏览器之争从上个世纪开就开始,已经持续了很长的时间.就在几年前,IE还是最主流的web浏览器.但现在形势完全不同了,人们都在笑话IE,纷纷转向其它浏览器.今天,我向大家分享一下针对IE的搞笑图片, ...

  3. 在windows下进行linux开发:利用Vagrant+virtualbox(ShowDoc与mp3dish的作者)

    1,介绍Vagrant 我们做web开发的时候经常要安装各种本地测试环境,比如apache,php,mysql,redis等等.出于个人使用习惯,可能我们还是比较习惯用windows.虽然说在wind ...

  4. 蓝桥杯之K好数问题

    问题描述 如果一个自然数N的K进制表示中任意的相邻的两位都不是相邻的数字,那么我们就说这个数是K好数.求L位K进制数中K好数的数目.例如K = 4,L = 2的时候,所有K好数为11.13.20.22 ...

  5. JSP、JSTL、EL

    Jsp Jsp内置对象: Response.Request.Page.pageContext.session.out.application.exception.config Out->jspW ...

  6. CSS:margin负数的使用

    给所有div加上边框=10px之后,再给所有div设置margin-left与margin-top;以及浮动(float:left) 因此时需要鼠标悬停效果:所以设置给div设置伪类:hover,然因 ...

  7. html基础标签-1-pre预格式标签

    pre预格式标签 code,tt标签 1 <!doctype html> 2 <html lang='zh-cn'> 3 <head> 4 <meta cha ...

  8. log4j 详解

      转载自:http://www.blogjava.net/hwpok/archive/2008/08/23/223891.html >>>>1. 概述<<< ...

  9. Heritrix个性化设置抓取目标

    本文是Heritrix的使用的高级篇,针对对Heritrix已经能够运行的码农朋友们! 我们在抓取网页的时候,网页的链接中往往会包含有js.css.图片.视频等文件,第一次执行抓取任务的时候,许多农民 ...

  10. Oracle 导入本地dmp文件 详细操作步骤

    以下操作均在命令行窗口中进行 /*连接数据库*/ C:\Users\hqbhonker>sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Prod ...