11using System ;
22using System . IO ;
3+ using System . Management . Automation . Runspaces ;
4+ using System . Management . Automation ;
35
46namespace Test_ShareFileSnapIn
57{
@@ -12,9 +14,9 @@ public class Utils
1214 private static string _sfFolder = "Folder1Q" ;
1315
1416 /// <summary>
15- /// C: \sflogin.sfps
17+ /// %LOCALAPPDATA%\ShareFile \sflogin.sfps
1618 /// </summary>
17- public static string LoginFilePath = @"C:\ sflogin.sfps";
19+ public static string LoginFilePath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "ShareFile" , " sflogin.sfps") ;
1820
1921 /// <summary>
2022 /// sf
@@ -25,20 +27,20 @@ public class Utils
2527 /// </summary>
2628 public static string ShareFileDrivePath = string . Format ( "{0}{1}" , ShareFileDriveLetter , ":" ) ;
2729 /// <summary>
28- /// sf:/My Files & Folders
30+ /// sf:/Personal Folders
2931 /// </summary>
30- public static string ShareFileHomeFolder = string . Format ( "{0}{1}" , ShareFileDrivePath , "/My Files & Folders" ) ;
32+ public static string ShareFileHomeFolder = string . Format ( "{0}{1}" , ShareFileDrivePath , "/Personal Folders" ) ;
3133
3234 /// <summary>
3335 /// sf:/Folder1
3436 /// </summary>
3537 public static string ShareFileFolder = string . Format ( "{0}{1}{2}" , ShareFileDrivePath , "/" , _localFolder ) ;
3638 /// <summary>
37- /// sf:/My Files & Folders/Folder1Q
39+ /// sf:/Personal Folders/Folder1Q
3840 /// </summary>
3941 public static string ShareFileFolderUploaded = string . Format ( "{0}{1}{2}" , ShareFileHomeFolder , "/" , _sfFolder ) ;
4042 /// <summary>
41- /// sf:/My Files & Folders/Folder1
43+ /// sf:/Personal Folders/Folder1
4244 /// </summary>
4345 public static string ShareFileFolderFullPath = string . Format ( "{0}{1}{2}" , ShareFileHomeFolder , "/" , _localFolder ) ;
4446 /// <summary>
@@ -50,28 +52,28 @@ public class Utils
5052 /// </summary>
5153 public static string ShareFileFileUploaded = string . Format ( "{0}{1}{2}" , ShareFileHomeFolder , "/" , _localFile ) ;
5254 /// <summary>
53- /// sf:/My Files & Folders/DeepText.txt
55+ /// sf:/Personal Folders/DeepText.txt
5456 /// </summary>
5557 public static string ShareFileFileFullPath = string . Format ( "{0}{1}{2}" , ShareFileHomeFolder , "/" , _sfFile ) ;
5658
5759 /// <summary>
58- /// D: \SFTemp
60+ /// %LOCALAPPDATA%\ShareFile \SFTemp
5961 /// </summary>
60- public static string LocalBaseFolder = @"D:\ SFTemp";
62+ public static string LocalBaseFolder = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "ShareFile" , " SFTemp") ;
6163 /// <summary>
62- /// D: \SFTemp\Folder1Q
64+ /// %LOCALAPPDATA%\ShareFile \SFTemp\Folder1Q
6365 /// </summary>
6466 public static string LocalFolder = string . Format ( "{0}{1}{2}" , LocalBaseFolder , @"\" , _sfFolder ) ;
6567 /// <summary>
66- /// D: \SFTemp\Folder1
68+ /// %LOCALAPPDATA%\ShareFile \SFTemp\Folder1
6769 /// </summary>
6870 public static string LocalFolderDownloaded = string . Format ( "{0}{1}{2}" , LocalBaseFolder , @"\" , _localFolder ) ;
6971 /// <summary>
70- /// D: \SFTemp\ToUpload.txt
72+ /// %LOCALAPPDATA%\ShareFile \SFTemp\ToUpload.txt
7173 /// </summary>
7274 public static string LocalFile = string . Format ( "{0}{1}{2}" , LocalBaseFolder , @"\" , _localFile ) ;
7375 /// <summary>
74- /// D: \SFTemp\DeepText.txt
76+ /// %LOCALAPPDATA%\ShareFile \SFTemp\DeepText.txt
7577 /// </summary>
7678 public static string LocalFileDownloaded = string . Format ( "{0}{1}{2}" , LocalBaseFolder , @"\" , _sfFile ) ;
7779
@@ -115,6 +117,16 @@ public static void DeleteLocalFolder(string path)
115117 }
116118 }
117119
120+ public static Runspace OpenRunspace ( )
121+ {
122+ const string moduleName = "ShareFile" ;
123+ InitialSessionState initial = InitialSessionState . CreateDefault ( ) ;
124+ initial . ImportPSModule ( new string [ ] { moduleName } ) ;
125+ var runspace = RunspaceFactory . CreateRunspace ( initial ) ;
126+ runspace . Open ( ) ;
127+ return runspace ;
128+ }
129+
118130 private static void DeleteLocalItemRecursive ( FileSystemInfo source )
119131 {
120132 if ( source is DirectoryInfo )
0 commit comments