473,468 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

My Documents path in C#

What is the best method to obtain the actual folder path to My Documents for
the current logged in user in C#?

Thanks,

Yosh
Nov 17 '05 #1
5 39971
Hi,

Take a look at Environment class, there you have methods to get it, IIRC
there is an enum with several folders that you use calling GetFolderPath()
method

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Yosh" <Yo**@nospam.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl...
What is the best method to obtain the actual folder path to My Documents
for the current logged in user in C#?

Thanks,

Yosh

Nov 17 '05 #2
1)
Environment.GetFolderPath(Environment.SpecialFolde r.Personal)

2)
Or the extreme way what is actually done by the GetFolderPath method but
with less checking :p

[DllImport("shfolder.dll", CharSet=CharSet.Auto)]
internal static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder,
IntPtr hToken, int dwFlags, System.Text.StringBuilder lpszPath);
[STAThread]
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder(260);
SHGetFolderPath(IntPtr.Zero, 5, IntPtr.Zero, 0, sb);
Console.WriteLine(sb);
Console.Read();
}
Gabriel Lozano-Morán
"Yosh" <Yo**@nospam.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl...
What is the best method to obtain the actual folder path to My Documents
for the current logged in user in C#?

Thanks,

Yosh

Nov 17 '05 #3
Is one method better than the other?

Do they both always return the My Documents path or is there a situation in
which one wouldn't?

Thanks,

Yosh

"Gabriel Lozano-Morán" <ga************@no-spam.com> wrote in message
news:uH**************@TK2MSFTNGP14.phx.gbl...
1)
Environment.GetFolderPath(Environment.SpecialFolde r.Personal)

2)
Or the extreme way what is actually done by the GetFolderPath method but
with less checking :p

[DllImport("shfolder.dll", CharSet=CharSet.Auto)]
internal static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder,
IntPtr hToken, int dwFlags, System.Text.StringBuilder lpszPath);
[STAThread]
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder(260);
SHGetFolderPath(IntPtr.Zero, 5, IntPtr.Zero, 0, sb);
Console.WriteLine(sb);
Console.Read();
}
Gabriel Lozano-Morán
"Yosh" <Yo**@nospam.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl...
What is the best method to obtain the actual folder path to My Documents
for the current logged in user in C#?

Thanks,

Yosh


Nov 17 '05 #4
I posted the two ways to let you know why I love .NET, you would offcourse
go for number 1 :)

Gabriel Lozano-Morán

"Yosh" <Yo**@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Is one method better than the other?

Do they both always return the My Documents path or is there a situation
in which one wouldn't?

Thanks,

Yosh

"Gabriel Lozano-Morán" <ga************@no-spam.com> wrote in message
news:uH**************@TK2MSFTNGP14.phx.gbl...
1)
Environment.GetFolderPath(Environment.SpecialFolde r.Personal)

2)
Or the extreme way what is actually done by the GetFolderPath method but
with less checking :p

[DllImport("shfolder.dll", CharSet=CharSet.Auto)]
internal static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder,
IntPtr hToken, int dwFlags, System.Text.StringBuilder lpszPath);
[STAThread]
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder(260);
SHGetFolderPath(IntPtr.Zero, 5, IntPtr.Zero, 0, sb);
Console.WriteLine(sb);
Console.Read();
}
Gabriel Lozano-Morán
"Yosh" <Yo**@nospam.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl...
What is the best method to obtain the actual folder path to My Documents
for the current logged in user in C#?

Thanks,

Yosh



Nov 17 '05 #5
ah yes... that's exactly what I chose.

Thanks Grabriel!

Yosh

"Gabriel Lozano-Morán" <ga************@no-spam.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I posted the two ways to let you know why I love .NET, you would offcourse
go for number 1 :)

Gabriel Lozano-Morán

"Yosh" <Yo**@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Is one method better than the other?

Do they both always return the My Documents path or is there a situation
in which one wouldn't?

Thanks,

Yosh

"Gabriel Lozano-Morán" <ga************@no-spam.com> wrote in message
news:uH**************@TK2MSFTNGP14.phx.gbl...
1)
Environment.GetFolderPath(Environment.SpecialFolde r.Personal)

2)
Or the extreme way what is actually done by the GetFolderPath method but
with less checking :p

[DllImport("shfolder.dll", CharSet=CharSet.Auto)]
internal static extern int SHGetFolderPath(IntPtr hwndOwner, int
nFolder, IntPtr hToken, int dwFlags, System.Text.StringBuilder
lpszPath);
[STAThread]
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder(260);
SHGetFolderPath(IntPtr.Zero, 5, IntPtr.Zero, 0, sb);
Console.WriteLine(sb);
Console.Read();
}
Gabriel Lozano-Morán
"Yosh" <Yo**@nospam.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl...
What is the best method to obtain the actual folder path to My
Documents for the current logged in user in C#?

Thanks,

Yosh



Nov 17 '05 #6

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

Similar topics

1
by: switter | last post by:
I am creating a document management systems using asp. I have been researching the different ways of handling the documents such as using the file system and storing the path in the db, and...
0
by: Grant_S | last post by:
I need to identify the path to a users "My Document" folder where the user has a roaming profile and their "My Documents" folder is mapped to a network share as the H drive (specifically H:\\ -...
4
by: ken | last post by:
I get error 13 type mismatch for this piece of code: With objWord .Visible = True .Documents.Open (CurrentProject.Path & "\tmp.doc") If Len() > 2 Then >>>>> .Documents.Save...
6
by: JuLiE Dxer | last post by:
Is there a way via C# to programmatically retrieve the full path name to folders like "My Documents" ?? I'm seeing examples with the use of Shell32 stuff I believe, SHGetSpecialFolderLocation...
9
by: dgk | last post by:
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...
6
by: (PeteCresswell) | last post by:
User wants to go this route instead of storing pointers in the DB and the documents outside. Only time I tried it was with only MS Word docs - and that was a loooong time ago - and it seemed to...
2
by: bstauffer | last post by:
Thanks in advance to anyone who has any ideas on this. I have an ASP.Net 2.0 website set up on a working production web server. The purpose of the site is to provide access to various documents...
8
by: Wernerh | last post by:
In vb6 I have the following script: FileCopy "C:\My Documents\support.xls", "C:\Support.xls" - when I run it it returns an error - Path not found. When I change it to FileCopy...
46
by: RAZZ | last post by:
Hello, Can anyone suggest me solution? I Need to manage different types of documents (doc,xls,ppt etc) in server. I have folder structure to maintain these documents in server. Say folder1 is...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.