File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -176,4 +176,13 @@ string text = SimpleFileHandler.Read("path/to/file.txt");
176176- appends text to a file
177177``` csharp
178178SimpleFileHandler .Append (" path/to/file.txt" , " Sample text 2" );
179+ ```
180+ ### ProjectToLocation
181+ - extract a file from the project to a given location
182+ ``` csharp
183+ SimpleFileHandler .ProjectToLocation (" SampleClass.cs" );
184+
185+ // Or
186+
187+ SimpleFileHandler .ProjectToLocation (" SampleClass.cs" , " path/to/destination" );
179188```
Original file line number Diff line number Diff line change 11using System . IO ;
2+ using System . Reflection ;
23
34namespace CSSimpleFunctions
45{
@@ -18,5 +19,41 @@ public static void Append(string FilePath, string Content)
1819 {
1920 File . AppendAllText ( FilePath , Content ) ;
2021 }
22+
23+ public static void ProjectToLocation ( string FileName )
24+ {
25+ try
26+ {
27+ if ( ! Path . GetDirectoryName ( FileName ) . Equals ( string . Empty ) && ! Directory . Exists ( Path . GetDirectoryName ( FileName ) ) )
28+ {
29+ Directory . CreateDirectory ( Path . GetDirectoryName ( FileName ) ) ;
30+ }
31+ FileStream ProjectFileStream = File . Create ( FileName ) ;
32+ Assembly . GetExecutingAssembly ( ) . GetManifestResourceStream ( Assembly . GetCallingAssembly ( ) . EntryPoint . DeclaringType . Namespace + "." + Path . GetFileName ( FileName ) ) . CopyTo ( ProjectFileStream ) ;
33+ ProjectFileStream . Close ( ) ;
34+ }
35+ catch
36+ {
37+ Console . WriteLine ( "Cannot copy project file. Please make sure the file's build action is set to 'Embedded Resource'." ) ;
38+ }
39+ }
40+
41+ public static void ProjectToLocation ( string FileName , string FilePath )
42+ {
43+ try
44+ {
45+ if ( ! Directory . Exists ( FilePath ) )
46+ {
47+ Directory . CreateDirectory ( FilePath ) ;
48+ }
49+ FileStream ProjectFileStream = File . Create ( Path . Combine ( FilePath , Path . GetFileName ( FileName ) ) ) ;
50+ Assembly . GetExecutingAssembly ( ) . GetManifestResourceStream ( Assembly . GetCallingAssembly ( ) . EntryPoint . DeclaringType . Namespace + "." + Path . GetFileName ( FileName ) ) . CopyTo ( ProjectFileStream ) ;
51+ ProjectFileStream . Close ( ) ;
52+ }
53+ catch
54+ {
55+ Console . WriteLine ( "Cannot copy project file. Please make sure the file's build action is set to 'Embedded Resource'." ) ;
56+ }
57+ }
2158 }
2259}
You can’t perform that action at this time.
0 commit comments