Getting NotV1SupportedException when creating a folder.
__Here's the stack trace:__
Microsoft.Win32.TaskScheduler.NotV1SupportedException: MyClass.createTask is not supported on Task Scheduler 1.0
at Microsoft.Win32.TaskScheduler.TaskFolder.CreateFolder(String subFolderName, String sddlForm, Boolean exceptionOnExists)
__Code:__
td.Actions.Add(new ExecAction(scheduleExePath, scheduleId));
TaskFolder tf = ts.RootFolder;
TaskFolder testFolder = null;
foreach (TaskFolder taskFolder in tf.SubFolders)
{
if (taskFolder.Name.Equals("ReportSchedule", StringComparison.OrdinalIgnoreCase))
{
testFolder = taskFolder;
}
}
if (testFolder == null)
testFolder = tf.CreateFolder("MyFolder");
__Environment:__
OS: Windows 10 / Windows 2012
Visual Studio 2013
.NET Framework 4.5.1
Task Scheduler Version: Release 2.5.21
Kindly advice, is there anything I am doing wrong?
Thanks
Mani
Comments: ** Comment from web user: dahall **
This one is easy and is a problem with your code. You have created the TaskService instance and have set the 'forceV1' parameter to 'true'. This forces the library to revert to the version created for Windows XP that does not support subfolders. You simply need to set that parameter to false and your code should work. Please note that you should protect against trying to create folders on any system older than Windows Vista. Also, you can use the tf.SubFolders.Exists method to see if the "ReportSchedule" subfolder has been created instead of the loop. It is much more efficient. I would do something like:
```C#
TaskFolder tf = ts.RootFolder;
TaskFolder testFolder = tf;
if (System.Environment.OSVersion.Version.Major >= 6)
{
if (!tf.SubFolders.Exists("ReportSchedule"))
testFolder = tf.CreateFolder("MyFolder");
else
testFolder = tf.SubFolders["ReportSchedule"];
}
```