Click here to Skip to main content
15,887,321 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My 'share folder' code is below:
VB
string strServer = @"ServerName";
string strShareFolder = @"D:\DD";
string strShareName = @"MS_Test";
string strShareDesc = @"Share to store";
EnCryptDecrypt.Share.ADSI_Net.NetApi32.NetError nRetVal = 0;
AD_ShareUtil shUtil = new AD_ShareUtil();
nRetVal = shUtil.CreateShare(strServer, strShareFolder, strShareName, strShareDesc, false);
if (nRetVal == EnCryptDecrypt.Share.ADSI_Net.NetApi32.NetError.NERR_Success)
{
Console.WriteLine("Share {0} created", strShareName);
}
else if (nRetVal == EnCryptDecrypt.Share.ADSI_Net.NetApi32.NetError.NERR_DuplicateShare)
{
Console.WriteLine("Share {0} already exists", strShareName);
}
else
Console.WriteLine("Share not created", strShareName);

String directory = @"D:\DD";
DirectorySecurity sec = Directory.GetAccessControl(directory);
NTAccount acct = new NTAccount("Everyone");
IdentityReference id = acct.Translate(typeof(NTAccount));
FileSystemAccessRule rule = new FileSystemAccessRule(acct, FileSystemRights.ListDirectory, AccessControlType.Allow);
sec.AddAccessRule(rule);
Directory.SetAccessControl(directory, sec);

I need to add a text file to a 'share folder' on the server.
The above code is fine when running to create a 'share folder' in the server.
When I open the network share folder in another machine, then it is open folder,
but do not open the file into that share folder.
Message shows 'Access denied'.

How can I access the file in that remote share folder?
Please help appreciated.
Posted
Updated 1-Feb-12 2:42am
v2
Comments
LittleYellowBird 1-Feb-12 8:42am    
Edited: added code segment and tidied.

1 solution

Whoops. Just reread the code instead of the explaination.

Your code is giving Everyone the ListDirectory permission, but nothing else. You may want to read over the documentation on the FileSystemRights enumeration to add more permissions, like CreateFiles, among others.

Keep in mind that there are both NTFS and Share permissions you need to setup. If you don't know how these work, stop working on the code now and start reading up on Windows Networking. You have to understand this stuff before you start writing code to set it up for you.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900