I have developed a setup project for my web application. I need to give the write permissions for a sub-folder. Because, in the runtime, my application will copy files in this folder. So that i need to give write access for this folder at the time of installation.
Can anybody help me to grand permissions for a web sub-folder at the time of installation?
You will need to create a library to run after the installation to set in Custom Actions of your Setup and Deployment project. Take a look to "http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx".
That article don´t treats about this, but you can see how you must to use Custom Actions.
However, I think more practical to use the special folders of current user. With special folders you don´t need to worrry about permissions. Take a look to
Environment.GetFolderPath to more informations.
There are another tool like this called "Isolated Storage". Take a look for
IsolatedStorage class.
Sorry about my English. I don´t speak English so much.
Actually I have finished my development process. So i am unable to go for the Isolated Storage system.
What I actually need is just to give the full permission for my folder which will hold some pictures (automatically these are generated) in the run time.
Also already i have used the custom actions in my setup project. but i dont know to develop the library which gives the permissions for my folder.
So please If you can, send me the source for the library. The permissions has to give for all web site users.
Take a look for "ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref8/html/M_System_IO_DirectoryInfo_SetAccessControl_1_b5965545.htm" from your Visual Studio Documentation (You can paste that address in your browser too).
At last I found the solution for providing the permissions to my web folder. herewith i have attached the code for all of you.
I have created a console application with the following. This application will be called from my msi setup file and i will pass the installation path as argument for this console application.
using System;
using System.Collections.Generic;
using System.Text;
namespace SetFolderPermission
{
class Program
{
static void Main(string[] args)
{
try
{
string myParam = "";
string myParam2 = "";
if (args.Length > 0)
{
myParam = args[0] + "\\MyFolder";
myParam2 = args[0] + "\\Reports\\MyConfig.xml";
}
Console.Write("Starting to apply folder permissions .... \n");
if (!System.IO.Directory.Exists(myParam))
{
System.IO.Directory.CreateDirectory(myParam);
}
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
dhanashivam
Member
87 Points
71 Posts
How to set permissions for a web folder at the time of installation.
May 02, 2008 10:24 AM|LINK
hi all,
I have developed a setup project for my web application. I need to give the write permissions for a sub-folder. Because, in the runtime, my application will copy files in this folder. So that i need to give write access for this folder at the time of installation.
Can anybody help me to grand permissions for a web sub-folder at the time of installation?
thanks in advance.
dhana.
mgodoy_desen...
Contributor
2539 Points
453 Posts
Re: How to set permissions for a web folder at the time of installation.
May 02, 2008 06:59 PM|LINK
You will need to create a library to run after the installation to set in Custom Actions of your Setup and Deployment project. Take a look to "http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx". That article don´t treats about this, but you can see how you must to use Custom Actions.
However, I think more practical to use the special folders of current user. With special folders you don´t need to worrry about permissions. Take a look to Environment.GetFolderPath to more informations.
There are another tool like this called "Isolated Storage". Take a look for IsolatedStorage class.
Sorry about my English. I don´t speak English so much.
dhanashivam
Member
87 Points
71 Posts
Re: How to set permissions for a web folder at the time of installation.
May 03, 2008 04:26 AM|LINK
Thanks for your reply.
Actually I have finished my development process. So i am unable to go for the Isolated Storage system.
What I actually need is just to give the full permission for my folder which will hold some pictures (automatically these are generated) in the run time.
Also already i have used the custom actions in my setup project. but i dont know to develop the library which gives the permissions for my folder.
So please If you can, send me the source for the library. The permissions has to give for all web site users.
Thanks.
Dhana.
mgodoy_desen...
Contributor
2539 Points
453 Posts
Re: How to set permissions for a web folder at the time of installation.
May 05, 2008 12:18 PM|LINK
Take a look for "ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref8/html/M_System_IO_DirectoryInfo_SetAccessControl_1_b5965545.htm" from your Visual Studio Documentation (You can paste that address in your browser too).
dhanashivam
Member
87 Points
71 Posts
Re: How to set permissions for a web folder at the time of installation.
May 13, 2008 05:03 AM|LINK
Hi everybody,
At last I found the solution for providing the permissions to my web folder. herewith i have attached the code for all of you.
I have created a console application with the following. This application will be called from my msi setup file and i will pass the installation path as argument for this console application.
using System;
using System.Collections.Generic;
using System.Text;
namespace SetFolderPermission
{
class Program
{
static void Main(string[] args)
{
try
{
string myParam = "";
string myParam2 = "";
if (args.Length > 0)
{
myParam = args[0] + "\\MyFolder";
myParam2 = args[0] + "\\Reports\\MyConfig.xml";
}
Console.Write("Starting to apply folder permissions .... \n");
if (!System.IO.Directory.Exists(myParam))
{
System.IO.Directory.CreateDirectory(myParam);
}
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "C:\\windows\\system32\\cacls.exe ";
myProcess.StartInfo.Arguments = myParam + " /e /t /c /p " + System.Environment.MachineName + "\\ASPNET:F";
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
myProcess.Start();
myProcess.WaitForExit();
myProcess.StartInfo.FileName = "C:\\windows\\system32\\cacls.exe ";
myProcess.StartInfo.Arguments = myParam + " /e /t /c /p NETWORKSERVICE:F";
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
myProcess.Start();
myProcess.WaitForExit();
myProcess.StartInfo.FileName = "C:\\windows\\system32\\cacls.exe ";
myProcess.StartInfo.Arguments = myParam2 + " /e /t /c /p everyone:F";
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
myProcess.Start();
myProcess.WaitForExit();
myProcess.StartInfo.FileName = "C:\\windows\\system32\\cacls.exe ";
myProcess.StartInfo.Arguments = myParam2 + " /e /t /c /p " + System.Environment.MachineName + "\\ASPNET:F";
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
myProcess.Start();
myProcess.WaitForExit();
Console.Write("\n\n\nProcess Finished .... \nPress any key to continue ...");
Console.ReadLine();
}
catch (Exception ex)
{
Console.Write(ex.Message);
Console.ReadLine();
}
}
}
}
Hope this will help you all. go to command prompt and type and execute "cacls.exe" for additional options available on it.
gspence
Member
2 Points
1 Post
Re: How to set permissions for a web folder at the time of installation.
May 13, 2008 03:24 PM|LINK
Thank you dhanashivam for posting your solution!