01.
$code
= @"
02.
using System;
03.
using System.IO;
04.
using System.Text;
05.
using System.Windows.Forms;
06.
07.
public
class
Program
08.
{
09.
[STAThread]
10.
public
static
void Main()
11.
{
12.
13.
OpenFileDialog openFileDialog =
new
OpenFileDialog();
14.
openFileDialog.Filter =
"テキスト|*.txt|全て|*.*"
;
15.
openFileDialog.FilterIndex = 2;
16.
openFileDialog.InitialDirectory = @
"C:\"
;
17.
18.
if
(openFileDialog.ShowDialog() != DialogResult.OK)
19.
{
20.
return
;
21.
}
22.
23.
Console.WriteLine(openFileDialog.FileName);
24.
25.
string path = openFileDialog.FileName;
26.
if
( File.Exists(path) )
27.
{
28.
Console.WriteLine(
"{0} は存在しています"
, path );
29.
}
30.
31.
32.
Encoding Enc = Encoding.GetEncoding(932);
33.
34.
try
35.
{
36.
using (StreamReader ReadFile =
new
StreamReader(path, Enc))
37.
{
38.
39.
string Text = ReadFile.ReadToEnd();
40.
41.
42.
ReadFile.Close();
43.
44.
Console.WriteLine(Text);
45.
}
46.
47.
}
48.
catch (Exception ex)
49.
{
50.
Console.WriteLine(ex.Message);
51.
}
52.
53.
Console.ReadLine();
54.
}
55.
}
56.
"@
57.
58.
Add-Type -Language CSharp -TypeDefinition
$code
-ReferencedAssemblies (
"System.Windows.Forms"
)
59.
60.
[Program]::Main()