Click here to Skip to main content
15,887,746 members
Home / Discussions / C#
   

C#

 
GeneralRe: Right Click Menu Pin
AhmedMasum5-Oct-09 23:01
AhmedMasum5-Oct-09 23:01 
GeneralRe: Right Click Menu Pin
Mycroft Holmes5-Oct-09 23:15
professionalMycroft Holmes5-Oct-09 23:15 
GeneralRe: Right Click Menu Pin
Muammar©5-Oct-09 23:34
Muammar©5-Oct-09 23:34 
GeneralRe: Right Click Menu Pin
AhmedMasum6-Oct-09 17:44
AhmedMasum6-Oct-09 17:44 
GeneralRe: Right Click Menu Pin
Muammar©6-Oct-09 21:01
Muammar©6-Oct-09 21:01 
QuestionAbout listbox use in DatagridView in window application Pin
sanjay307845-Oct-09 21:34
sanjay307845-Oct-09 21:34 
AnswerRe: About listbox use in DatagridView in window application Pin
Richard MacCutchan5-Oct-09 23:58
mveRichard MacCutchan5-Oct-09 23:58 
QuestionHow to give Write permission for a Folder? Pin
MikeSharp5-Oct-09 19:29
MikeSharp5-Oct-09 19:29 
Hi,

How to enable write permission for a folder , I googled internet for some sample programs, I got few programs but these were on the basis on Domain name and User name! I would like to know how this can be achieved on a standalone system ? Do we require Domain name and User Name for changing permission of a folder?

I have attached a small program of with this issue, kindly review it, it is executing but there is write permission is not enabled with this.

using System;
using System.IO;
using System.Security.AccessControl;
using System.Windows.Forms;

namespace FileSystemExample
{
    class FileExample
    {
        public static void Main()
        {
            string DomainName = System.Environment.UserDomainName.ToString();
            DomainName += @"\";
            string AccountName = System.Environment.UserName.ToString();
            DomainName += AccountName;
                 

            try
            {
                string folderName = @"C:\Inetpub\ftproot";

                Console.WriteLine("Adding access control entry for "
                    + folderName);

                // Add the access control entry to the file.
                AddFileSecurity(folderName,DomainName,FileSystemRights.WriteExtendedAttributes, AccessControlType.Allow);

                Console.WriteLine("Removing access control entry from "
                    + folderName);

                // Remove the access control entry from the file.

                  RemoveFileSecurity(folderName, DomainName,FileSystemRights.WriteExtendedAttributes, AccessControlType.Allow);

                Console.WriteLine("Done.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }

        // Adds an ACL entry on the specified file for the specified account.
        public static void AddFileSecurity(string folderName, string account,
            FileSystemRights rights, AccessControlType controlType)
        {


            // Get a FileSecurity object that represents the
            // current security settings.
            FileSecurity fSecurity = File.GetAccessControl(folderName);

            // Add the FileSystemAccessRule to the security settings.
            fSecurity.AddAccessRule(new FileSystemAccessRule(account,
                rights, controlType));

            // Set the new access settings.
            File.SetAccessControl(folderName, fSecurity);

        }

        // Removes an ACL entry on the specified file for the specified account.
        public static void RemoveFileSecurity(string folderName, string account,
            FileSystemRights rights, AccessControlType controlType)
        {

            // Get a FileSecurity object that represents the
            // current security settings.
            FileSecurity fSecurity = File.GetAccessControl(folderName);

            // Remove the FileSystemAccessRule from the security settings.
            fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,
                rights, controlType));

            // Set the new access settings.
            File.SetAccessControl(folderName, fSecurity);

        }
    }
}


Mike
AnswerRe: How to give Write permission for a Folder? Pin
Calla5-Oct-09 21:59
Calla5-Oct-09 21:59 
GeneralRe: How to give Write permission for a Folder? Pin
MikeSharp5-Oct-09 23:43
MikeSharp5-Oct-09 23:43 
GeneralRe: How to give Write permission for a Folder? Pin
stancrm6-Oct-09 1:19
stancrm6-Oct-09 1:19 
Questionremoving the last character of textbox Pin
NarendraSinghJTV5-Oct-09 19:02
NarendraSinghJTV5-Oct-09 19:02 
AnswerRe: removing the last character of textbox Pin
Christian Graus5-Oct-09 19:21
protectorChristian Graus5-Oct-09 19:21 
GeneralRe: removing the last character of textbox Pin
Rajesh Anuhya5-Oct-09 19:42
professionalRajesh Anuhya5-Oct-09 19:42 
GeneralRe: removing the last character of textbox Pin
Christian Graus5-Oct-09 20:05
protectorChristian Graus5-Oct-09 20:05 
GeneralRe: removing the last character of textbox Pin
Rajesh Anuhya5-Oct-09 20:11
professionalRajesh Anuhya5-Oct-09 20:11 
GeneralRe: removing the last character of textbox Pin
Christian Graus5-Oct-09 20:30
protectorChristian Graus5-Oct-09 20:30 
GeneralRe: removing the last character of textbox Pin
NarendraSinghJTV6-Oct-09 1:41
NarendraSinghJTV6-Oct-09 1:41 
GeneralRe: removing the last character of textbox Pin
NarendraSinghJTV6-Oct-09 1:26
NarendraSinghJTV6-Oct-09 1:26 
GeneralRe: removing the last character of textbox Pin
NarendraSinghJTV6-Oct-09 1:28
NarendraSinghJTV6-Oct-09 1:28 
GeneralRe: removing the last character of textbox Pin
NarendraSinghJTV6-Oct-09 1:45
NarendraSinghJTV6-Oct-09 1:45 
GeneralRe: removing the last character of textbox Pin
PIEBALDconsult6-Oct-09 4:58
mvePIEBALDconsult6-Oct-09 4:58 
GeneralRe: removing the last character of textbox Pin
NarendraSinghJTV6-Oct-09 18:43
NarendraSinghJTV6-Oct-09 18:43 
AnswerRe: removing the last character of textbox Pin
AhmedMasum5-Oct-09 22:37
AhmedMasum5-Oct-09 22:37 
GeneralRe: removing the last character of textbox Pin
Christian Graus6-Oct-09 0:02
protectorChristian Graus6-Oct-09 0:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.