I am trying to write text file to a Share as follows:
IntPtr token = IntPtr.Zero;
bool isSuccess = LogonUser("UserName", "Domain", "Password!", LOGON32_LOGON_NEW_CREDENTIALS, LOGON32_PROVIDER_DEFAULT, ref token);
if (isSuccess)
{
using (WindowsImpersonationContext person = new WindowsIdentity(token).Impersonate())
{
using (StreamWriter error = new StreamWriter(@"\\IP\FileStore\logs\error_" + name + "_" + DateTime.Now.ToString("d") + ".txt", true))
{
error.Write(ex.Message);
error.Flush();
error.Close();
}
person.Undo();
}
}
And I am getting this error below, How can I fix this?
Best Regards.
And I am getting this error below, How can I fix this?
Best Regards.
System.IO.IOException was unhandled
Message=Configuration information could not be read from the domain controller, either because the machine is unavailable, or access has been denied.
Source=mscorlib
StackTrace:
konum: System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
konum: 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)
konum: System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
konum: System.IO.StreamWriter.CreateFile(String path, Boolean append)
konum: System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
konum: System.IO.StreamWriter..ctor(String path, Boolean append)
konum: ?.?(String A_0)
konum: ?.?(IntPtr A_0, IntPtr A_1)
konum: ?.?(Int32 A_0, IntPtr A_1, IntPtr A_2)
konum: System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg, HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)
konum: System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
konum: System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
konum: System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
konum: System.Windows.Forms.Application.Run(Form mainForm)
konum: ?.?()
InnerException:

Hemant KumarRank #1,202 · 1.5K reputationPosted Feb 25, 2012, 4:05 AM EST
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { long lastCode = 28110000; int padSize = (lastCode == 0) ? 1 : (int)Math.Log10(lastCode) + 1; String filename = @"C:\Documents and Settings\All Users\Desktop\" + lastCode + "_sequentialCodes.txt"; StreamWriter writer = new StreamWriter(filename, false, Encoding.ASCII); writer.AutoFlush = true; for (int i = 1; i lastCode + 1; i++) { writer.WriteLine(i.ToString().PadLeft(padSize, '0')); if (i % 100 == 0) { Console.WriteLine(i.ToString()); } } writer.Close(); Console.WriteLine(); Console.WriteLine(lastCode + " codes written to \n" + filename); Console.Read(); } } }RaysefoRank #4,173 · 360 reputationPosted Feb 25, 2012, 7:44 AM EST
Does your code help for this error?
Configuration information could not be read from the domain controller, either because the machine is unavailable, or access has been denied.
RaysefoRank #4,173 · 360 reputationPosted Feb 29, 2012, 4:24 AM EST