Solved

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

Posted on 2006-07-12
38
2,473 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
  • 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 275 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 225 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now