在实际开发中,如果用的文件名不能确定位置。或名字。可以使用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. Python 字符串格式化示例

    先看代码吧. #!/usr/bin/env python #-*- coding: utf-8 -*- __author__ = 'jiang' __creattime__ = '2015/10/31 ...

  2. linux printf和fork()问题小结

    总结如下: printf("father begin"); pid_t pid; pid = fork(); ) { ) { printf("father out&quo ...

  3. MFC CArchive实现保存到二进制文件

    先看一下效果图 BOOL Save2File() { BOOL bOpenFileDialog = FALSE; ---------------------------------- ① BOOL b ...

  4. Python核心编程笔记--随机数

    #第一步引入模块 import random #第二步生成随机数 print random.randint(1,3);#[1,2,3]注意这里是闭区间.

  5. mysql timestamp 值不合法问题

    Create Table: CREATE TABLE `RecruitmentDesc` ( `sn` int(11) NOT NULL AUTO_INCREMENT COMMENT '编号(自增字段 ...

  6. bootstrap-dialog的使用

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 30款基本UX工具 - 用户测试与反馈工具

    日期:2013-9-5  来源:GBin1.com 在上一篇30款基本UX工具 - 思维流程工具 & 原型工具中,我们提到了10款用于头脑风暴和原型创建的工具,用于帮助我们在用户体验上可以做的 ...

  8. Matlab中取模(mod)与取余(rem)的区别

    取模(mod)与取余(rem)是不同的,通常取模运算也叫取余运算,它们返回结果都是余数. rem和mod唯一的区别在于: 当x和y的正负号一样的时候,两个函数结果是等同的:当x和y的符号不同时,rem ...

  9. win7+cygwin+hadoop+eclipse

    1.Cygwin : Net    下的:openssh,openssl Base  下的:sed (若需要Eclipse,必须sed)默认即可 Devel 下的:subversion(建议安装) 2 ...

  10. 关于cell中添加子视图 复用重叠问题的解决方法

    问题本质:   因为你要添加的子视图并不是在自定义的cell中实现的,而是根据系统给的UITableViewCell这个类创建的实例,每次进图 cellForRow方法都会创建一个cell,每次都要创 ...