Victor Charles
asked on
Help with creating folder on user's PC
Hi,
I am using clickonce technolody to deploy my project, would like to create a folder on user's PC to save a file, does the user need admin rights to create a folder on the C drive? If not, How do you create a folder (i.e. AP40) on the C drive using VB.NET?
Thanks,
Victor
I am using clickonce technolody to deploy my project, would like to create a folder on user's PC to save a file, does the user need admin rights to create a folder on the C drive? If not, How do you create a folder (i.e. AP40) on the C drive using VB.NET?
Thanks,
Victor
Something like this illustrates what I am referencing:
Imports System.IO
Module Module1
Sub Main()
CreateFolder("C:\Test")
' Creating a user specific folder
CreateFolder(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "EE_Q28615221\AP40"))
' Creating an application specific folder
CreateFolder(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "EE_Q28615221\AP40"))
Console.ReadLine()
End Sub
Public Sub CreateFolder(ByVal folder As String)
Dim dir As DirectoryInfo = New DirectoryInfo(folder)
Try
If Not dir.Exists Then
dir.Create()
Console.WriteLine("Directory {0}; created.", dir.FullName)
Else
Console.WriteLine("Directory {0}; already exists.", dir.FullName)
End If
Catch ex As Exception
dir = New DirectoryInfo(folder)
If Not dir.Exists Then
Console.WriteLine("There was an error creating the directory - {0}.", dir.FullName)
End If
Console.WriteLine("{0}.", ex.Message)
Finally
If dir IsNot Nothing Then
dir = Nothing
End If
End Try
End Sub
End Module
Produces the following output --saige-
ASKER
Hi,
Thank you for both inputs, due to admin rights issues with Vista or higher, better approach will be to allow users to select the folder they want to save the file.
Thanks,
Victor
Thank you for both inputs, due to admin rights issues with Vista or higher, better approach will be to allow users to select the folder they want to save the file.
Thanks,
Victor
ASKER
Hi,
Do you know if all windows pc have a c:\Temp folder, might be easier to install to the temp folder.
Do you know if all windows pc have a c:\Temp folder, might be easier to install to the temp folder.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You.
Open in new window
Produces the following output -But, you asked a key question. It depends on the operating system (Vista and above, YES). In order to provide admin rights on the creation of the folder, you could use an API call to ShellExecute. You could also instruct the user to right-click on the installer and run as administrator. Or, you could use a manifest file to instruct the application that it needs administrative rights.But this raises another couple of questions.
Is the folder user or application specific?
Is there a dependency that requires the folder to be on the root of C:?
If the folder is specific to your application and is only needed for the installation, it is better to use a temporary file location that already exists and can be accessed by way of the environment variables. If it is permanent and required, then if it is user specific, put it in the Users Application Data folder (again accessible through environment variables). Otherwise, store it in the application folder.
-saige-