在实际开发中,如果用的文件名不能确定位置。或名字。可以使用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. 走进C标准库(7)——"string.h"中函数的实现memcmp,memcpy,memmove,memset

    我的memcmp: int memcmp(void *buf1, void *buf2, unsigned int count){ int reval; while(count && ...

  2. 导出excel java实现

    1.前台页面代码: <tr> <td><input dataId="excel" type="button" value=&quo ...

  3. 使用百度语音识别REST API,做全平台语音识别

    百度语音开发介绍文档: http://yuyin.baidu.com/docs/asr# 使用语音识别,需要在百度申请一个应用,然后拿到API Key和Secret Key,然后才可以使用语音识别 p ...

  4. nautilus-open-terminal右键随处打开终端

    Nautilus-Open-Terminal : 可随处打开终端的 Nautilus 插件 nautilus-open-terminal-0.17-4.el6.x86_64 是一个让你随处都可以打开终 ...

  5. 利用OpenCV和MFC对话框建设一个有滑动条控制的播放器--转

    (一)问题的提出: OpenCV有一个很简单的播放视频文件并加载滑动条的程序,但是如何用MFC对话框来创建一个有滑动条控制的播放器呢,网络上四处搜索都没有代码可以参考,下的都是些骗子链接文件,很过分, ...

  6. collection系列用法-defaultdict()

    defaultdict() 定义以及作用 返回一个和dictionary类似的对象,和dict不同主要体现在2个方面: 可以指定key对应的value的类型. 不必为默认值担心,换句话说就是不必担心有 ...

  7. 07.20 html5的适配flexible

    <script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js"> ...

  8. iPhone 禁止 Safari 页面上下拖动反弹

    解决方法:  <body ontouchmove="event.preventDefault()"  >     手机端设置:  <meta content=&q ...

  9. javascript中数组排序

    在javascript中Array类中提供了一个可以为数组排序的方法Array.sort(): 但此方法排序方式是按照unicode码进行的排序,若将整数型加入到数组元素中, 排出的结果往往达不到我们 ...

  10. JS操作JSON的方法总结

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式.同时,JSON是 JavaScript 原生格式,这意 ...