如何使用Winform应用程序从系统中获取下载的Pdf文件的路径
本文关键字:下载 Pdf 文件 路径 获取 Winform 何使用 应用程序 系统 | 更新日期: 2023-09-27 18:29:34
我正在创建windows应用程序我正在下载pdf文件这些文件存储在每个系统中下载的路径是(它们的特定路径它们保存的地方所以我必须向用户显示路径文件是在哪里使用Winform下载的所以我如何获得这些路径请帮助我。
尽早回复感谢
我不知道你的英语不好、含糊不清和缺乏代码示例是什么意思。我的最佳猜测是,你正试图识别用户的"下载"目录?
以下是我的做法(考虑到这就是你的意思):
// Identify the users "user" directory
string userPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile);
DirectoryInfo user = new DirectoryInfo(userPath);
if (user.Exists)
{
// Identify the "%USERPROFILE%'Downloads" directory on Windows Vista, 7, 8 systems.
DirectoryInfo downloads = new DirectoryInfo(user + @"'Downloads");
if (downloads.Exists)
{
// return the full path "C:'Users'USERNAME'Downloads"
return downloads.FullName;
}
else
{
// Couldn't find it, maybe they're on Windows XP
string xpDocs = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
DirectoryInfo xpDownloads = new DirectoryInfo(xpDocs + @"'Downloads");
if (xpDownloads.Exists)
{
// return the full path "C:'Documents and Settings'USERNAME'My Documents'Downloads"
return xpDownloads.FullName;
}
else
{
// Couldn't identify a "Downloads" directory in either location
throw new DirectoryNotFoundException("Cannot identify the users 'Downloads' directory.");
}
}
}
else
{
// Couldn't identify a "%USERPROFILE%" folder. Shouldn't ever happen...
throw new DirectoryNotFoundException("Cannot identify the users default directory.");
}