私はC#の初心者です。実行時に file という名前の IP アドレスを作成し、それらのファイルにデータを書き込みたいという問題があります。このコードを目的に使用していますが、機能していません。それは私に例外を与えています:
First chance exception of type 'System.NotSupportedException' occurred in mscorlib.dll
例外は次のとおりです。
System.NotSupportedException: The given path's format is not supported.
そして、これは私のコードです:
System.Diagnostics.Debug.Write( content);
handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReadCallback), state);
System.Diagnostics.Debug.WriteLine(
"Read {0} bytes from socket. \n Data : {1}", content);
string dir = @"C:\AppRecord";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
File.WriteAllText(Path.Combine(dir,
"log"+handler.RemoteEndPoint.ToString()+".txt"), content);
これはスタック トレースです。
A first chance exception of type 'System.NotSupportedException' occurred in mscorlib.dll
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, AccessControlActions control, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding)
at System.IO.File.WriteAllText(String path, String contents, Encoding encoding)
at System.IO.File.WriteAllText(String path, String contents)
at ServerWService.Service1.AsynchronousSocketListener.ReadCallback(IAsyncResult ar)