473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Physical vs Logical My Documents question

dgk
Is there some built in way to know whether a physical folder path is
'My Documents" for a specific user? I can always use xxx.StartsWith to
compare it to the enumeration returned by the Personal folder, but it
seems a bit inelegant.
Nov 21 '05 #1
9 2480
dgk wrote:
Is there some built in way to know whether a physical folder path is
'My Documents" for a specific user? I can always use xxx.StartsWith to
compare it to the enumeration returned by the Personal folder, but it
seems a bit inelegant.


HKCU\Software\Microsoft\Windows\CurrentVersion\Exp lorer\Shell Folders
That contains the location for all the Special folders for that user.

HTH,
Tibby
Nov 21 '05 #2
DGK,

Although I am not clear about what you write, because you use your own
probably your own mnemonics of classes.

I assume that you with the Enum means the enum in the Environment class and
not an own build Enum.

Than it seems for me in combination with the path class, from what I think
you mean with xxx and the method to get the full path in that what I think
you mean with Start, a complete normal method that you use.

I hope this helps,

Cor
Nov 21 '05 #3
Hi,

Environment.GetFolderPath(Environment.SpecialFolde r.Personal)
returns the path to My Documents.

Ken
-----------------
"dgk" <so******************@zero-spam-hotmail.com> wrote in message
news:6m********************************@4ax.com...
Is there some built in way to know whether a physical folder path is
'My Documents" for a specific user? I can always use xxx.StartsWith to
compare it to the enumeration returned by the Personal folder, but it
seems a bit inelegant.
Nov 21 '05 #4
dgk
On Tue, 2 Aug 2005 02:40:42 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
Hi,

Environment.GetFolderPath(Environment.SpecialFolde r.Personal)
returns the path to My Documents.

Ken
-----------------
"dgk" <so******************@zero-spam-hotmail.com> wrote in message
news:6m********************************@4ax.com.. .
Is there some built in way to know whether a physical folder path is
'My Documents" for a specific user? I can always use xxx.StartsWith to
compare it to the enumeration returned by the Personal folder, but it
seems a bit inelegant.


Sorry, I should be more specific. I have the user pick the folder
where a database will be kept, defaulting to "My Documents\ProductX",
where ProductX is the name of my program. When FolderBrowserDialog is
used to have the user pick a folder, and they choose "My Documents",
it returns the physical address as the SelectedPath, not "My
Documents" which is what the user expects to see. So I don't want to
subsequently show the physical location, I want to show "My
Documents".

I check to see if the physical path returned begins with the physical
My Documents path, and then show it as My Documents to the user.
Nothing major, I've already written the trivial code to handle it but
it just seemed that there would be a built in function (oops, Shared
Class method) that would deal with the physical vs logical
implementation of the Special Folders.

Nov 21 '05 #5
DGK,

I have a routine that does it the same way as you do.

Cor
Nov 21 '05 #6
dgk,
In addition to the other comments.

I was thinking that the System.Uri.MakeRelative function might help. Which
is not specifically what you want, but may give you an indication of what
you want...

The Uri.MakeRelative function "determines the difference between two Uri
instances". There is a constructor on Uri that takes a root URI and
"appends" a relative path.

The System.IO.Path.IsPathRooted can be used to determine if the path itself
is relative or absolute.

One of the advantages of using the Uri object in your function is that it
removes superfluous segments, such as "/" and resolves ".." in the path.

One could create a function similar to:

Public Function IsRoot(ByVal rootPath As String, ByVal sourcePath As
String) As Boolean
Dim root As New Uri(rootPath)
Dim source As Uri
If Path.IsPathRooted(sourcePath) Then
source = New Uri(sourcePath)
Else
source = New Uri(root, sourcePath)
End If
Dim relative As String = root.MakeRelative(source)
Return Not Path.IsPathRooted(relative)
End Function

Unfortunately it doesn't work, per se.
Going back to your original idea, I would modify the above to use StartWith
on Uri.AbsolutePath. Something like:

Public Function IsRoot(ByVal rootPath As String, ByVal sourcePath As
String) As Boolean
Dim root As New Uri(rootPath & "\"c)
Dim source As Uri
If Path.IsPathRooted(sourcePath) Then
source = New Uri(sourcePath)
Else
source = New Uri(root, sourcePath)
End If
Return source.AbsolutePath.StartsWith(root.AbsolutePath)
End Function
Dim myDocuments As String =
Environment.GetFolderPath(Environment.SpecialFolde r.Personal) & "\"c
Dim path1 As String = "D:\Documents and Settings\Jay\My
Documents\Visual Studio Projects"
Dim path2 As String = "D:\Documents and Settings\dgk\My
Documents\Visual Studio Projects"
Dim path3 As String = "D:\Documents and Settings\Jay\..\Jay\My
Documents\Visual Studio Projects"
Dim path4 As String = "Visual Studio Projects"

Debug.WriteLine(myDocuments, "My Documents")
Debug.WriteLine(IsRoot(myDocuments, path1), path1)
Debug.WriteLine(IsRoot(myDocuments, path2), path2)
Debug.WriteLine(IsRoot(myDocuments, path3), path3)
Debug.WriteLine(IsRoot(myDocuments, path4), path4)
Hope this helps
Jay
"dgk" <so******************@zero-spam-hotmail.com> wrote in message
news:6m********************************@4ax.com...
| Is there some built in way to know whether a physical folder path is
| 'My Documents" for a specific user? I can always use xxx.StartsWith to
| compare it to the enumeration returned by the Personal folder, but it
| seems a bit inelegant.
Nov 21 '05 #7
dgk,
| I check to see if the physical path returned begins with the physical
| My Documents path, and then show it as My Documents to the user.
| Nothing major, I've already written the trivial code to handle it but
Uri.MakeRelative will do that!

Try something like:

Dim myDocuments As New
Uri(Environment.GetFolderPath(Environment.SpecialF older.Personal), True)
Dim dialog As New SaveFileDialog
If dialog.ShowDialog() = DialogResult.OK Then
Dim toUri As New Uri(dialog.FileName, True)
MessageBox.Show(myDocuments.MakeRelative(toUri), "Safe As")
End If

Hope this helps
Jay

"dgk" <so******************@hot-nospamp-mail.com> wrote in message
news:pm********************************@4ax.com...
| On Tue, 2 Aug 2005 02:40:42 -0400, "Ken Tucker [MVP]"
| <vb***@bellsouth.net> wrote:
|
| >Hi,
| >
| > Environment.GetFolderPath(Environment.SpecialFolde r.Personal)
| >returns the path to My Documents.
| >
| >Ken
| >-----------------
| >"dgk" <so******************@zero-spam-hotmail.com> wrote in message
| >news:6m********************************@4ax.com.. .
| >Is there some built in way to know whether a physical folder path is
| >'My Documents" for a specific user? I can always use xxx.StartsWith to
| >compare it to the enumeration returned by the Personal folder, but it
| >seems a bit inelegant.
| >
|
| Sorry, I should be more specific. I have the user pick the folder
| where a database will be kept, defaulting to "My Documents\ProductX",
| where ProductX is the name of my program. When FolderBrowserDialog is
| used to have the user pick a folder, and they choose "My Documents",
| it returns the physical address as the SelectedPath, not "My
| Documents" which is what the user expects to see. So I don't want to
| subsequently show the physical location, I want to show "My
| Documents".
|
| I check to see if the physical path returned begins with the physical
| My Documents path, and then show it as My Documents to the user.
| Nothing major, I've already written the trivial code to handle it but
| it just seemed that there would be a built in function (oops, Shared
| Class method) that would deal with the physical vs logical
| implementation of the Special Folders.
|
Nov 21 '05 #8
Doh!!

Here is a sample using the FolderBrowserDialog:

Dim dialog As New FolderBrowserDialog
If dialog.ShowDialog() = DialogResult.OK Then
Dim rootUri As New
Uri(Environment.GetFolderPath(dialog.RootFolder), True)
Dim toUri As New Uri(dialog.SelectedPath, True)
MessageBox.Show(rootUri.MakeRelative(toUri), "Safe As")
End If

Notice that I use the FolderBrowserDialog.RootFolder property to determine
the root path to make the relative path from.

Hope this helps
Jay

"dgk" <so******************@hot-nospamp-mail.com> wrote in message
news:pm********************************@4ax.com...
| On Tue, 2 Aug 2005 02:40:42 -0400, "Ken Tucker [MVP]"
| <vb***@bellsouth.net> wrote:
|
| >Hi,
| >
| > Environment.GetFolderPath(Environment.SpecialFolde r.Personal)
| >returns the path to My Documents.
| >
| >Ken
| >-----------------
| >"dgk" <so******************@zero-spam-hotmail.com> wrote in message
| >news:6m********************************@4ax.com.. .
| >Is there some built in way to know whether a physical folder path is
| >'My Documents" for a specific user? I can always use xxx.StartsWith to
| >compare it to the enumeration returned by the Personal folder, but it
| >seems a bit inelegant.
| >
|
| Sorry, I should be more specific. I have the user pick the folder
| where a database will be kept, defaulting to "My Documents\ProductX",
| where ProductX is the name of my program. When FolderBrowserDialog is
| used to have the user pick a folder, and they choose "My Documents",
| it returns the physical address as the SelectedPath, not "My
| Documents" which is what the user expects to see. So I don't want to
| subsequently show the physical location, I want to show "My
| Documents".
|
| I check to see if the physical path returned begins with the physical
| My Documents path, and then show it as My Documents to the user.
| Nothing major, I've already written the trivial code to handle it but
| it just seemed that there would be a built in function (oops, Shared
| Class method) that would deal with the physical vs logical
| implementation of the Special Folders.
|
Nov 21 '05 #9
dgk
On Tue, 2 Aug 2005 13:13:12 -0500, "Jay B. Harlow [MVP - Outlook]"
<Ja************@msn.com> wrote:
dgk,
In addition to the other comments.

I was thinking that the System.Uri.MakeRelative function might help. Which
is not specifically what you want, but may give you an indication of what
you want...
...

OUCH! And I was thinking that my solution wasn't elegant. But this is
interesting stuff and I will investigate it. I hadn't thought about
the .. problem. I didn't realize that that could ever be returned by a
function. Always more to learn. Add URI to the list.
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Hennessy | last post by:
I'm looking for people's opinions and feedback regarding the design of the application tier, and how to best logically separate out the Data Access from the Business Object's. Per the Microsoft...
0
by: chris6995 | last post by:
I'm looking for a way to programatically query for the association between a physical device (i.e. removable USB storage) and it's logical drive letter. I've gone through Win32_LogicalDisk,...
9
by: Olumide | last post by:
Thats the question. I know about virtual memory, and the MMU. I just wonder if array members guaranteed to be contiguous in physical memory (and if so, why). Thanks, Olumide
7
by: jimdscudder | last post by:
How can I use WMI or a WqlObjectQuery to find the hard drive letter of the physical drive location index. For example the following code will give me the physical drive location:...
1
by: MattM | last post by:
Looking at a tutorial for Asp.Net 2.0 using Northwind, the DAL was built by dragging the tables on to an XSN to create a dataTable object for each table in the database. The BLL was then mapped for...
4
by: tobin | last post by:
Hi folks, We're looking for a CMS system for our organisation, and we're picking potential solutions. We need something that is scalable cause we're a growing company, so there's potentially...
3
by: nkumarin001 | last post by:
Hi, a) Why oracle architecture is divided into 2 types logical and physical structure? b) What is the use of logical structure in oracle as it does not consume any space if so then...
1
by: gdia44 | last post by:
Hello, This is my first post to this forum. I'm working through an exercise where I am required to 'design and describe' the logical and physical structure for a case study. I've made quite...
1
by: Jose Barragan | last post by:
Can anyone tell me whats the difference between logical pages and physical pages and how are logical pages created on the fly? Thanks
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.