Monday, 1 February 2016

Create a directory permition of installation folder in asp.net desktop application


Create a directory permition of installation folder in asp.net desktop application

You can us only the color block of code .

 [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var connectionstring = ConfigurationManager.AppSettings["connectb02C_coreDB"].ToString().Trim();
            b02C_core.DataAccess.DataAccess obj = new DataAccess.DataAccess();
            if (string.IsNullOrWhiteSpace(connectionstring) && connectionstring == "")
            {
                string sFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                try
                {
                    DirectoryInfo info = new DirectoryInfo(sFolder);
                    WindowsIdentity self = System.Security.Principal.WindowsIdentity.GetCurrent();
                    DirectorySecurity ds = info.GetAccessControl();
                    ds.AddAccessRule(new FileSystemAccessRule(self.Name,
                    FileSystemRights.FullControl,
                    InheritanceFlags.ObjectInherit |
                    InheritanceFlags.ContainerInherit,
                    PropagationFlags.None,
                    AccessControlType.Allow));
                    info.SetAccessControl(ds);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Oops! Error in setup. ","Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Application.Run(new SqlSetUpForm());
            }

No comments:

Post a Comment