如何使用Winform应用程序从系统获取下载的Pdf文件的路径

时间:2014-11-07 05:16:33

标签: c# .net

我正在创建Windows应用程序我正在下载pdf文件那些文件存储到每个系统中下载的路径是(它们的特定路径它们正在保存所以我必须显示用户的路径使用Winform下载文件的方式如何我可以帮助我吗?

尽早回复 谢谢

1 个答案:

答案 0 :(得分:0)

我不确定你的英语,模糊和缺乏代码示例是什么意思。我最好的猜测是你试图识别用户的“下载”目录?

以下是我如何去做(鉴于这就是你的意思):

// 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.");
}