我想获取所选文件夹的位置并尝试此代码,它没有给我任何错误,但没有用 [英] i want to get the location of the selected folder and tried this code, it doesn't give me any errors but it doesnt work

查看:46
本文介绍了我想获取所选文件夹的位置并尝试此代码,它没有给我任何错误,但没有用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void BtnBrowse_Click(object sender, EventArgs e)
        {
            //====== Create folder dialog box object
            FolderBrowserDialog objFolderDialog = new FolderBrowserDialog();
            //===== Pass object as Parameter and get Selected network folder
            TextBox1.Text  = GetNetworkFolders(objFolderDialog);
        }

        public static string GetNetworkFolders(FolderBrowserDialog FolderBrowserDialog)
        {
            //======= Get type of Folder Dialog bog
            Type type = FolderBrowserDialog.GetType();
            //======== Get Fieldinfo for rootfolder.
            System.Reflection.FieldInfo fieldInfo = type.GetField("rootFolder", BindingFlags.NonPublic | BindingFlags.Instance);
            //========= Now set the value for Folder Dialog using DirectCast
            //=== 18 = Network Neighborhood is the root
            fieldInfo.SetValue(FolderBrowserDialog, (Environment.SpecialFolder)18);
            //==== if user click on Ok, then it will return the selected folder.
            //===== otherwise return the blank string.
            if (FolderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                return FolderBrowserDialog.SelectedPath;
            }
            else
            {
                return "";
            }
        }

推荐答案

建议您在此处详细说明您要执行的操作:是否要选择网络上的计算机,并且然后在所选计算机中选择一个文件夹?

您会收到什么错误消息?

请参阅此CP文章:"Rama Krishna Vavilala的.NET文件夹浏览器组件" [ ^ ].

如果那不起作用,请参阅:这是基于Vavilala的CP文章[
Suggest you tell us more here about exactly what you are trying to do: are you trying to select a computer on a network, and then select a folder within that selected computer ?

And what error message are you getting ?

See this CP article: "Folder Browser component for .NET By Rama Krishna Vavilala"[^].

If that doesn''t work then see: which is based on Vavilala''s CP article[^].

Are you using a version of .NET before 3.5; the reason I ask is I remember something on StackOverFlow about you would get an error trying to cast a number to an Environment.SpecialFolder if that were the case.

good luck, Bill



为什么不使用fb.rootfolder属性....它返回根文件夹路径....
Hi,
Why dont you use fb.rootfolder property....it returns the root folder path....


这篇关于我想获取所选文件夹的位置并尝试此代码,它没有给我任何错误,但没有用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆