Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-07-12
38
Medium Priority
?
2,911 Views
Last Modified: 2012-06-21
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
Comment
Question by:hesaigo999ca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 13
  • 8
  • +3
38 Comments
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 17089935
MyComputer is not really a folder, what are you trying to do?
0
 
LVL 41

Expert Comment

by:graye
ID: 17090226
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17090368
Emmet, that is MyComputer not MyDocuments.

Bob
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:topdog770
ID: 17090763
MyComputer is the only SpecialFolder that doesn't map to a directory or folder name
0
 
LVL 7

Expert Comment

by:whatsit2002
ID: 17090937
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
 

Author Comment

by:hesaigo999ca
ID: 17090967
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
 

Author Comment

by:hesaigo999ca
ID: 17090978
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
 

Author Comment

by:hesaigo999ca
ID: 17093359
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
 

Author Comment

by:hesaigo999ca
ID: 17103035
hello?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17103560
Do you want to set the root folder for the FolderBrowserDialog?

Bob
0
 

Author Comment

by:hesaigo999ca
ID: 17109961
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17110027
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
 

Author Comment

by:hesaigo999ca
ID: 17110110
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17110138
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
 

Author Comment

by:hesaigo999ca
ID: 17110227
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17110445
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
 

Author Comment

by:hesaigo999ca
ID: 17110758
...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
 

Author Comment

by:hesaigo999ca
ID: 17122599
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17129265
Sorry, not a hardcore C++ developer.

Bob
0
 
LVL 12

Expert Comment

by:topdog770
ID: 17131648
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17131722
And, how does that work with the WebBrowser's Navigate method?

Bob
0
 
LVL 12

Expert Comment

by:topdog770
ID: 17131732
That's what I was just going to try out!
0
 
LVL 12

Accepted Solution

by:
topdog770 earned 1100 total points
ID: 17131765
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17131777
Very cool--great job!!!

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17132107
Where did you find the reference to that magic?

Bob
0
 
LVL 12

Expert Comment

by:topdog770
ID: 17132116
wow... let me think...

0
 
LVL 12

Expert Comment

by:topdog770
ID: 17132121
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17132131
Right into my bag-o-tricks went that code in a different form.

Thanks,
Bob
0
 
LVL 12

Expert Comment

by:topdog770
ID: 17132151
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17132190
2003 = project with multiple single-purpose classes, 2005 snippet manager

Bob
0
 
LVL 12

Expert Comment

by:topdog770
ID: 17132197
cool, thanks.. haven't played with the snippet manager at all, yet.
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 900 total points
ID: 17132263
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
 

Author Comment

by:hesaigo999ca
ID: 17132586
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17132813
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
 

Author Comment

by:hesaigo999ca
ID: 17132839
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17132862
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
 

Author Comment

by:hesaigo999ca
ID: 17148583
 ; )
0
 

Author Comment

by:hesaigo999ca
ID: 17148919
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question