What is the best method to obtain the actual folder path to My Documents for
the current logged in user in C#?
Thanks,
Yosh 5 40001
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.co m> wrote in message
news:uC******** ******@TK2MSFTN GP12.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
1)
Environment.Get FolderPath(Envi ronment.Special Folder.Personal )
2)
Or the extreme way what is actually done by the GetFolderPath method but
with less checking :p
[DllImport("shfo lder.dll", CharSet=CharSet .Auto)]
internal static extern int SHGetFolderPath (IntPtr hwndOwner, int nFolder,
IntPtr hToken, int dwFlags, System.Text.Str ingBuilder lpszPath);
[STAThread]
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder(2 60);
SHGetFolderPath (IntPtr.Zero, 5, IntPtr.Zero, 0, sb);
Console.WriteLi ne(sb);
Console.Read();
}
Gabriel Lozano-Morán
"Yosh" <Yo**@nospam.co m> wrote in message
news:uC******** ******@TK2MSFTN GP12.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
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******** ******@TK2MSFTN GP14.phx.gbl... 1) Environment.Get FolderPath(Envi ronment.Special Folder.Personal )
2) Or the extreme way what is actually done by the GetFolderPath method but with less checking :p
[DllImport("shfo lder.dll", CharSet=CharSet .Auto)] internal static extern int SHGetFolderPath (IntPtr hwndOwner, int nFolder, IntPtr hToken, int dwFlags, System.Text.Str ingBuilder lpszPath); [STAThread] static void Main(string[] args) { StringBuilder sb = new StringBuilder(2 60); SHGetFolderPath (IntPtr.Zero, 5, IntPtr.Zero, 0, sb); Console.WriteLi ne(sb); Console.Read(); }
Gabriel Lozano-Morán
"Yosh" <Yo**@nospam.co m> wrote in message news:uC******** ******@TK2MSFTN GP12.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
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.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.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******** ******@TK2MSFTN GP14.phx.gbl... 1) Environment.Get FolderPath(Envi ronment.Special Folder.Personal )
2) Or the extreme way what is actually done by the GetFolderPath method but with less checking :p
[DllImport("shfo lder.dll", CharSet=CharSet .Auto)] internal static extern int SHGetFolderPath (IntPtr hwndOwner, int nFolder, IntPtr hToken, int dwFlags, System.Text.Str ingBuilder lpszPath); [STAThread] static void Main(string[] args) { StringBuilder sb = new StringBuilder(2 60); SHGetFolderPath (IntPtr.Zero, 5, IntPtr.Zero, 0, sb); Console.WriteLi ne(sb); Console.Read(); }
Gabriel Lozano-Morán
"Yosh" <Yo**@nospam.co m> wrote in message news:uC******** ******@TK2MSFTN GP12.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
ah yes... that's exactly what I chose.
Thanks Grabriel!
Yosh
"Gabriel Lozano-Morán" <ga************ @no-spam.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.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.co m> wrote in message news:%2******** ********@TK2MSF TNGP10.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******** ******@TK2MSFTN GP14.phx.gbl... 1) Environment.Get FolderPath(Envi ronment.Special Folder.Personal )
2) Or the extreme way what is actually done by the GetFolderPath method but with less checking :p
[DllImport("shfo lder.dll", CharSet=CharSet .Auto)] internal static extern int SHGetFolderPath (IntPtr hwndOwner, int nFolder, IntPtr hToken, int dwFlags, System.Text.Str ingBuilder lpszPath); [STAThread] static void Main(string[] args) { StringBuilder sb = new StringBuilder(2 60); SHGetFolderPath (IntPtr.Zero, 5, IntPtr.Zero, 0, sb); Console.WriteLi ne(sb); Console.Read(); }
Gabriel Lozano-Morán
"Yosh" <Yo**@nospam.co m> wrote in message news:uC******** ******@TK2MSFTN GP12.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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 actually storing the
document in the db. I like the idea of storing it in the database much
better because I can allow users to manage documents themselves (I already
have the code in place to do it if I decide), having a central system with
the...
|
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:\\ - where the "My
Received Files" folder path then is H:\\My Refeceived Files. The double
\\ is not an escape character as subfolders only have sinvle "\" when I
am doing some investigation of paths in code).
It appears that the code, below, that I...
|
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 (CurrentProject.Path & "\" & &
".doc")
Else
|
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
and I have no knowledge nor experience using such stuff. I've seen
some examples pertaining to these special folders but it's all Greek
to me and I'm sure somebody here could explain it 100 times quicker
|
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 folder, but it
seems a bit inelegant.
| |
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 me like there were performance issues at the time.
How about the different types? The MS docs I would expect Access to
differentiate and handle appropriately (i.e. .DOC and .XLS).. but how about
..PDF? and can I stash a .TXT document in the...
|
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 including .doc, .xls, .pdf, etc. Once a user signs in, a
customized treeview of documents is displayed. These documents and
their hierarchial relationship have been previously configured using a
seperate application. When a user clicks on a...
|
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 "C:\Support.xls", "C:\Support1.xls"
Or any other variation of c:\....... it runs perfectly.
Is the any reasonable explination why it would not see "c:\My Documents" as a valid drive path??
|
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 having all doc files; folder2 is having all xls files
and so on.
Now these documents should not be able to get access through the url
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |