如何获取文件的路径 [英] how to get path of a file
本文介绍了如何获取文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好!
i想知道如何在任何地方获取保存在PC中的文件地址..
使用c#window应用程序获取其完整路径...我只知道文件名,但不知道它保存的地址。怎么做??? ??? div div =h2_lin>解决方案
你可能需要来在PC中的任何位置根据文件名搜索文件。
请参阅:如何使用Visual C#递归搜索目录 [ ^ ]
您好。你的问题不明显。你执行保存操作吗?
如果你使用saveFileDialog.Create一个按钮并试试这个:
private void GetPathButton_Click( object sender,RoutedEventArgs e)
{
string filePath = ;
SaveFileDialog saveFileDialog = new SaveFileDialog();
bool ? result = saveFileDialog.ShowDialog();
if (result.Value)
{
// < span class =code-comment>获取完整路径
filePath = saveFileDialog.FileName;
// 获取文件名
string fileName = saveFileDialog.SafeFileName;
}
}
您好,
您可以使用System.IO.FileInfo类
fileInfo = new FileInfo(fileName);
fileInfo.DirectoryName; // 这将提供具有文件的文件夹路径
hi everybody!!
i want to know that how to get the address of a file saved in PC anywhere..
to get its full path using c# window application...i only know the file name but not its address where it is saved..how to do this???
解决方案
You probably need to search a file based on its filename, anywhere in your PC.
See for instance: How to recursively search directories by using Visual C#[^].
Hi. your question isn't obvious. do you perform saving operation ?
if you use saveFileDialog.Create a button and try this:
private void GetPathButton_Click(object sender, RoutedEventArgs e) { string filePath = ""; SaveFileDialog saveFileDialog = new SaveFileDialog(); bool? result = saveFileDialog.ShowDialog(); if (result.Value) { //To get full path filePath = saveFileDialog.FileName; //To get file name string fileName = saveFileDialog.SafeFileName; } }
Hi,
you can use the class System.IO.FileInfo
fileInfo= new FileInfo(fileName); fileInfo.DirectoryName; //This will give the folder path which is having the file
这篇关于如何获取文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文