Register  |  Login



Earn money by sharing your knowledge through Quomon's revenue sharing program

Question

Status: Closed Points: 125 Time: 15:06 - Oct 11, 2007  

sathyapri

Drive Name

I have a urgent query in C#, please let me know if you can be of any help.

I have an UI where in i need to upload docs, so when we click on a button I have set it to open "My Documents" and it does perfectly well, but the same on a Server it opens the server's local "My documents", but I need to open the My documents folder of logged in User which is nothing but my local box "My DOcuments" that getz mapped when i Login to server.

This would generally be like C$ on Client (V:) or C$ on Client (M:), so all i want to know is how can I get this newly mapped drive name ie V: / M: in Windwos application using C#

Example

In my local box it would be

C:\Documents and Settings\<userName>\My Documents

In server it would be mapped drive of my local box which would be of any name

M:\Documents and Settings\<userName>\My Documents or

V:\Documents and Settings\<userName>\My Documents

Thanks for your timely help,

Categories:

Answer Discussion
Tutorials

 

Q&A System for Websites and Corporate Collaboration

Advertisement

  • Generates significant organic traffic for websites
  • Saves companies money, resources, and time

oracleofDelphi

Date:: Oct 12, 2007

Time:: 12:18

sounds like you need to only referrence the current user's my documents.
have you tried
"%userprofile%\my documents"

sathyapri

Date:: Oct 12, 2007

Time:: 14:57

can u tell this in a C# code

sathyapri

Date:: Oct 12, 2007

Time:: 15:10

If i am going to use the %userprofile% then its going to giv em only the logged in servers local drive, but I want logged in usere's local drive whcih u would contain logged in users my documents whcih is equivalent to the docs he sees when he is at his desktop \My Documents

oracleofDelphi

Date:: Oct 12, 2007

Time:: 17:19

ok, then try this function:
Environment.GetFolderPath(Environment.SpecialFolde r.Personal).ToString();

this returns the registry value that's listed in
HKCU\Software\Microsoft\windows\currentversion\explorer\Shell folders\Personal

sathyapri

Date:: Oct 12, 2007

Time:: 17:39

If I am going to run this line on the server, it would return me that servers' local folder (C:), but I need access to the mapped client drive which would be either U: or V: or any other as set by the admin on that system. so I need to find out that drive name.

Hope this help,

thanks for your time

oracleofDelphi

Date:: Oct 13, 2007

Time:: 12:11

no, the client's mapped drive is written in the hkcu registry.
When you set your server to use either roaming profiles or redirect the my documents folder, the redirection is contained in the above mentioned registry key. This will not work if you've just simply assigned the user a home folder within active directory, then the my documents folder isn't even redirected.
Not too sure what version of server the admin is using, in server 2003 folder redirection isn't set through mapped drives anyway, it's a group policy setting. once that is set, the workstation loads the registry remotely from the domain controller making much of the local registry null and void. In the above case, the HKCU path would be entirely overwritten with some UNC path like \\servername\home folders\user name\my documents
using the code should allow you to bypass even knowing what drive or redirection is used.
What sounds more likely is that your admin has created a logon script that maps a drive to the server and also created a desktop shortcut that points back to this mapped drive and named it "my documents"
If this is the case, you should be able to look at the logon scripts to determine what drive is mapped.
to see the logon script from a workstation, open explorer (not iexplore) and go to:
1. if your admin simply set scripts in Active Directory:
\\<domaincontrollername>\SYSVOL\<fqdn>\scripts\
2. If your admin used group policy objects to set scripts:
\\<domaincontrollername>\SYSVOL\<fqdn>\<policy>\user\scripts\
logon
you may have to go through a couple of policy folders to find the right one. Also, if there's nothing in '2' then we know that folder redirection isn't being used either and the my documents short cut method is being used. if this is the case, you must examine the code in '1' which should be a simple batch file, openable in notepad.

sathyapri

Date:: Oct 17, 2007

Time:: 14:52

Thanks for your time, I was able to get the solution by looping thru all the drives in the system and whenever the drive is of type "Network" i access my folder "My documents" else break out.

But now I have another thing to be done, I want access remove persmissions to server local drives. do you have any idea

oracleofDelphi

Date:: Oct 17, 2007

Time:: 17:04

Probably the best way to do this is to set up a new security group and set deny read access to that group.
open "active directory user's and computers" and navigate to the users folder.
(for cleanliness you may want to create a new organizational folder)
Create a new security group and name it "Local_Drive_Access_On_Servername" (1) or what ever you want, the more descriptive the better.
The reason why we're creating a new security group is simply because it adheres to a best practice approach.
open up my computer and right click local drive c: and click on the security tab.
Click "Edit" (2)
add the name from (1). and check the deny column for Read permissions only.
go ahead and select OK for the warning that pops up saying denials take precedence over allows. Just make sure you never add any of the builtin users (especially administrator) to the group. ok out of this window and repeat for any other drives.
Finally, add the respective users to the group.
Find the group you've created in active Directory (1) and go to its' properties. Click on the members tab and add the users you want to apply this to.

To undo this, return to the screen mentioned at (2) and highlight the group name and select Remove.

sathyapri

Date:: Oct 17, 2007

Time:: 17:20

I have an Upload Doc in UI and when I click on that button, I open up to see a File Dialog and in that we have a combo box from where we could select the files from any drive and in that I don't want the users to see the local drives of that server, but only the shared drive.

Is it someway possible to disable drop down list itself?

I am trying to do something like below but it isn't working fine

// Create a permission set.
PermissionSet myPermissionSet = new PermissionSet(PermissionState.None);
myPermissionSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.NoAccess, "N:\\Users"));
// Deny all permissions on 'TEMP' folder.
myPermissionSet.Deny();

FileIOPermission f = new FileIOPermission(PermissionState.None);
f.AllLocalFiles = FileIOPermissionAccess.NoAccess;

Please suggest

oracleofDelphi

Date:: Oct 18, 2007

Time:: 15:32

I'm trying to research whether your functions apply to windows folder permissions or if there is a separate database that houses these permissions.

sathyapri

Date:: Oct 29, 2007

Time:: 15:27

Sorry, for having to reply so late I found a solution for that, I did a validation on the OK button of the fiel dialog, so whenever they select any file other than shared drive I throw an message to them. Thanks for all your help

Question Answered

This question has been closed, and points have been rewarded to the following experts:

oracleofDelphi: 125

You're welcome however to comment or give additional information or if you wish, you have the ability to write a Tutorial in the Tutorial Area.

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

No tutorials have been submitted yet. Want to be the first?

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top servers Experts

View More

Rank

Expert

Points

1.

oracleofDelphi

332

2.

PeterNZ

190

3.

rcastagna

62

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es