Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3005
  • Last Modified:

string tmp = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) does not work

string tmp = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer)
does not work, as it resolves into "" which is not what I need, I need the actual path...
anyone know how to do this, with this virtual folder???
0
hesaigo999ca
Asked:
hesaigo999ca
  • 14
  • 13
  • 8
  • +3
2 Solutions
 
Ravi SinghSenior Software EngineerCommented:
MyComputer is not really a folder, what are you trying to do?
0
 
grayeCommented:
Hummm.... it works for me

Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) returns the full path to my "MyDocuments" folder.

Are you running this under the context of a User?  (not a Web application, or service, etc)?
0
 
Bob LearnedCommented:
Emmet, that is MyComputer not MyDocuments.

Bob
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
topdog770Commented:
MyComputer is the only SpecialFolder that doesn't map to a directory or folder name
0
 
whatsit2002Commented:
hesaigo999ca,

Can you tell us why you need the path to the "My Computer" folder? What do you wish to do with it? Perhaps there is a way around the issue that topdog770 mentioned.

Thank you.

Jason
0
 
hesaigo999caAuthor Commented:
I know this...I have read some articles about how using the Browser Folder Dialog
to try and bypass this problem, however I still cannot resolve it....the example
is at  http://www.xoc.net/works/tips/folderbrowserdialog.asp  however I would need a string representation to pass into the axWebBrowser object for navigation purposes...
so it resolves to strings only and guess what microsoft does not have a string resolve to
MyNetwork, nor MyComputer....which sucks...these are the only 2 that I would need...

any ideas anyone...i will add more points if need be.

ps- that is correct the MyDocuments folder does work, just not the MyCOmputer folder...as it is virtual and resolves to ""
0
 
hesaigo999caAuthor Commented:
ps - if anyone can get the example I showed at http://www.xoc.net/works/tips/folderbrowserdialog.asp to resolve a string...
please post it and I will try this and accept it if it works...
Thanks in advance
0
 
hesaigo999caAuthor Commented:
I need the path to these folders as they are dynamic per user and each user has their own version of what is inside these folders...user a will have diff. network neighboorhood they user b on same machine
0
 
hesaigo999caAuthor Commented:
hello?
0
 
Bob LearnedCommented:
Do you want to set the root folder for the FolderBrowserDialog?

Bob
0
 
hesaigo999caAuthor Commented:
anything that can resolve into a hard coded path to place inside a string variable
I would accept something like FolderBrowserDialog.RootPath.ToString()....
if it actually resolved the path for the MyComputer / MyNetwork folders...
I have tried many ways so far without success...but the link at http://www.xoc.net/works/tips/folderbrowserdialog does not seem to work for me...
maybe I am doing something wrong....
any thoughts are welcome....

ps- how does anyone resolve this path when they create their own application ...using the win32 apis??? I would use this too, if it could resolve a string with the proper path to
the folders....

at this point I am up for anything...

0
 
Bob LearnedCommented:
That wasn't an explanation--it only confused me more.

1) It sounds like you are still trying to get a hard path My Computer and My Network, which isn't possible.

2) The FolderBrowserDialog.RootFolder is an enum that tells the dialog which folder to set as the root for the dialog.

3) So, what are you really trying to do?

Bob
0
 
hesaigo999caAuthor Commented:
so far I can get the example to set the proper folder path in the folderbrowserdialogue, but I cant get a string representation of this path, only "18"...which I guess is the hexidecimal value passed in as CsIdl.Network...

any thoughts on how to get that string?
0
 
Bob LearnedCommented:
Why do you need a string representation?  You still haven't gotten to the root of that question?  What are you going to do with that string?

I am going to keep asking this question, until I get a good answer, and I haven't heard one yet.

Bob
0
 
hesaigo999caAuthor Commented:
I have already answered this question...because the axWebBrowser object's
navigate method only accepts strings...and it is capable of going unto the user's local
machine just like IE, so therefor this would allow me to open up web pages,
http:// etc.... and files...c:\windows.... except that the virtual representation of
ceratin folders are not available in the Environment.SpecialFolder enumerations...
which leads me to this post....hopefully someone out there has already worked on this and has gotten this to work....a proper string representation of the folder selected
in the SetRootFolder example shown above

Hope this explains all...
0
 
Bob LearnedCommented:
Ok, with all that said over and over again, there isn't an easy way to do this with the web browser control.  My Computer and My Network are not folders.  There might be a WinAPI call, but we would have to find it.

Bob
0
 
hesaigo999caAuthor Commented:
...I just thought there might be a property in the FolderBrowserDialogue that I could
access after Setting its RootFolder....to get a string to use???


0
 
hesaigo999caAuthor Commented:
funny...i thought this would have been easy for the more hardcore developers that have worked with c++ and accessed those hard to get informations from windows...
0
 
Bob LearnedCommented:
Sorry, not a hardcore C++ developer.

Bob
0
 
topdog770Commented:
const string MyComputer = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
const string MyDocuments  = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}";
const string MyNetworkPlaces = "::{208D2C60-3AEA-1069-A2D7-08002B30309D}";
const string Printers = "::{2227A280-3AEA-1069-A2DE-08002B30309D}";
const string RecycleBin = "::{645FF040-5081-101B-9F08-00AA002F954E}";
const string Tasks = "::{D6277990-4C6A-11CF-8D87-00AA0060F5BF}";

System.Windows.Forms.OpenFileDialog dlg = new OpenFileDialog();
dlg.InitialDirectory = MyComputer;
dlg.ShowDialog();

0
 
Bob LearnedCommented:
And, how does that work with the WebBrowser's Navigate method?

Bob
0
 
topdog770Commented:
That's what I was just going to try out!
0
 
topdog770Commented:
Works without any extra modification.

private void Form1_Load(object sender, System.EventArgs e)
{
       const string MyComputer = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
       axWebBrowser1.Navigate(MyComputer);
}
0
 
Bob LearnedCommented:
Very cool--great job!!!

Bob
0
 
Bob LearnedCommented:
Where did you find the reference to that magic?

Bob
0
 
topdog770Commented:
wow... let me think...

0
 
topdog770Commented:
0
 
Bob LearnedCommented:
Right into my bag-o-tricks went that code in a different form.

Thanks,
Bob
0
 
topdog770Commented:
Anytime, anyone can provide you with a new piece of information, it's a great day to be alive!!

How do you store all the information and data you've collected here?
0
 
Bob LearnedCommented:
2003 = project with multiple single-purpose classes, 2005 snippet manager

Bob
0
 
topdog770Commented:
cool, thanks.. haven't played with the snippet manager at all, yet.
0
 
Bob LearnedCommented:
Here is what I came up with:

using System;

public class EnvironmentFolders
{

  public enum DialogFolder
  {
    ApplicationData = Environment.SpecialFolder.ApplicationData,
    CommonApplicationData = Environment.SpecialFolder.CommonApplicationData,
    CommonProgramFiles = Environment.SpecialFolder.CommonProgramFiles,
    Cookies = Environment.SpecialFolder.Cookies,
    Desktop = Environment.SpecialFolder.Desktop,
    DesktopDirectory = Environment.SpecialFolder.DesktopDirectory,
    Favorites = Environment.SpecialFolder.Favorites,
    History = Environment.SpecialFolder.History,
    InternetCache = Environment.SpecialFolder.InternetCache,
    LocalApplicationData = Environment.SpecialFolder.LocalApplicationData,
    MyComputer = Environment.SpecialFolder.MyComputer,
    MyMusic = Environment.SpecialFolder.MyMusic,
    MyPictures = Environment.SpecialFolder.MyPictures,
    MyDocuments = Environment.SpecialFolder.Personal,
    NetworkPlaces,
    Printers,
    ProgramFiles = Environment.SpecialFolder.ProgramFiles,
    Programs = Environment.SpecialFolder.Programs,
    Recent = Environment.SpecialFolder.Recent,
    RecycleBin,
    SendTo = Environment.SpecialFolder.SendTo,
    StartMenu = Environment.SpecialFolder.StartMenu,
    Startup = Environment.SpecialFolder.Startup,
    System = Environment.SpecialFolder.System,
    Tasks,
    Templates = Environment.SpecialFolder.Templates
  }
 
  public static string GetSpecialFolderPath(DialogFolder directory)
  {
    const string MyComputer = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
    const string NetworkPlaces = "::{208D2C60-3AEA-1069-A2D7-08002B30309D}";
    const string Printers = "::{2227A280-3AEA-1069-A2DE-08002B30309D}";
    const string RecycleBin = "::{645FF040-5081-101B-9F08-00AA002F954E}";
    const string Tasks = "::{D6277990-4C6A-11CF-8D87-00AA0060F5BF}";
 
    switch (directory)
    {
      case DialogFolder.MyComputer:
        return MyComputer;
      case DialogFolder.NetworkPlaces:
        return NetworkPlaces;
      case DialogFolder.Printers:
        return Printers;
      case DialogFolder.RecycleBin:
        return RecycleBin;
      case DialogFolder.Tasks:
        return Tasks;
      default:
        return Environment.GetFolderPath((Environment.SpecialFolder)directory);
    }
  }

}

Bob
0
 
hesaigo999caAuthor Commented:
I am increasing the points seeing as you both have had a hand in it, topdog with being able to get a string representation (codus to u dude) and thelearnedone with having a full implementation with enumerations and all, I will accept both and split...

thanks guys....and by the way, I have to say this is not documented anywhere on microsoft's
website, are these strings/resolutions from the registry, do they have more mappings then just the ones you have listed here...and where could i find the reason why this works, and not the Environment.SplecialFolder etc...

Thanks again guys...
0
 
Bob LearnedCommented:
The registry key is:

Name = My Computer
HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}

There are 3 keys:
InfoTip
IntroText
LocalizedString

Each of these values use a call to @%SystemRoot%\system32\SHELL32.dll, with an numeric identifier:
  Example for MyComputer:  @%SystemRoot%\system32\SHELL32.dll,-9216

You can look for @%SystemRoot%\system32\SHELL32.dll in the registry, and any of the 3 keys, and see what the name of the folder is.

Bob
0
 
hesaigo999caAuthor Commented:
You guys amaze me, everytime...I love this website....I just wish that more
of the veterans would help share their knowledge, as I find sometimes, not everyone is
willing to go the extra mile.....

thanks again to the both of you, and thanks for that explanation, it makes sense now, as I am reading the registry as we speak to see what other virtual paths
they have aside from the ones listed here.....you learn soemthing new and important everyday!

    : )
0
 
Bob LearnedCommented:
Well, if I go the extra mile, then I can learn something new myself, so that I can keep my reputation as "The Learned One".

Bob
0
 
hesaigo999caAuthor Commented:
 ; )
0
 
hesaigo999caAuthor Commented:
More easy points over at http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21926457.html
in case you guys wanted some more points...
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 14
  • 13
  • 8
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now