C#截取文件的文件夹地址
-
创建文件
1 if (!File.Exists(file_name)) 2 { 3 File.Create(file_name).Close(); 4 }
using System.IO;
如果没有.Close(),则要立即打开这个文件,软件会提示错误。
还可以使用.Dispose()方法。
-
截取文件的文件夹地址
private string get_fold_path(string file_name) { string temp; int index = file_name.LastIndexOf('\\'); temp = file_name.Remove(index); return temp; }
-
直接打开网页
using System.Diagnostics; Process.Start("http://www.ahut.edu.cn");
这个是指定用户设置的默认浏览器大开.
可以指定IE打开网页
Process.Start("IEXPLORE.EXE", "www.youtube.com");
-
打开保存文件对话框
使用SaveFileDialog控件。
if (saveFileDialog1.ShowDialog() == DialogResult.OK) { fileName = saveFileDialog1.FileName; MessageBox.Show("已选择文件夹:" + fileName, "选择文件夹提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }